Spaces:
Runtime error
Runtime error
zhangxiaochen commited on
auto
Browse files
app.py
CHANGED
|
@@ -1,23 +1,3 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from transformers import BertForSequenceClassification
|
| 3 |
-
from transformers import BertTokenizer
|
| 4 |
-
import torch
|
| 5 |
|
| 6 |
-
|
| 7 |
-
model=BertForSequenceClassification.from_pretrained('IDEA-CCNL/Erlangshen-Roberta-330M-Sentiment')
|
| 8 |
-
|
| 9 |
-
def predict(input_text):
|
| 10 |
-
predictions = model(torch.tensor([tokenizer.encode(input_text)]))
|
| 11 |
-
predictions=torch.nn.functional.softmax(predictions.logits,dim=-1)
|
| 12 |
-
print(predictions)
|
| 13 |
-
return input_text, {p["label"]: p["score"] for p in predictions}
|
| 14 |
-
|
| 15 |
-
gradio_app = gr.Interface(
|
| 16 |
-
fn=predict,
|
| 17 |
-
inputs="text",
|
| 18 |
-
outputs="text",
|
| 19 |
-
title="我能做中文文本的情绪二分类",
|
| 20 |
-
)
|
| 21 |
-
|
| 22 |
-
if __name__ == "__main__":
|
| 23 |
-
gradio_app.launch()
|
|
|
|
| 1 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
+
gr.load("models/IDEA-CCNL/Erlangshen-Roberta-330M-Sentiment").launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|