Spaces:
Runtime error
Runtime error
zhangxiaochen
commited on
Commit
β’
dc772a7
1
Parent(s):
748b73a
1st try
Browse files- app.py +19 -4
- requirements.txt +2 -0
app.py
CHANGED
@@ -1,7 +1,22 @@
|
|
1 |
import gradio as gr
|
|
|
|
|
|
|
2 |
|
3 |
-
|
4 |
-
|
5 |
|
6 |
-
|
7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
+
from transformers import BertForSequenceClassification
|
3 |
+
from transformers import BertTokenizer
|
4 |
+
import torch
|
5 |
|
6 |
+
tokenizer=BertTokenizer.from_pretrained('IDEA-CCNL/Erlangshen-Roberta-330M-Sentiment')
|
7 |
+
model=BertForSequenceClassification.from_pretrained('IDEA-CCNL/Erlangshen-Roberta-330M-Sentiment')
|
8 |
|
9 |
+
def predict(input_text):
|
10 |
+
predictions = model(torch.tensor([tokenizer.encode(text)]))
|
11 |
+
predictions=torch.nn.functional.softmax(predictions.logits,dim=-1)
|
12 |
+
return input_text, {p["label"]: p["score"] for p in predictions}
|
13 |
+
|
14 |
+
gradio_app = gr.Interface(
|
15 |
+
fn=predict,
|
16 |
+
inputs="text",
|
17 |
+
outputs="text",
|
18 |
+
title="ζθ½εδΈζζζ¬ηζ
η»ͺδΊεη±»",
|
19 |
+
)
|
20 |
+
|
21 |
+
if __name__ == "__main__":
|
22 |
+
gradio_app.launch()
|
requirements.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
transformers
|
2 |
+
torch
|