zhangxiaochen commited on
Commit
dc772a7
β€’
1 Parent(s): 748b73a
Files changed (2) hide show
  1. app.py +19 -4
  2. requirements.txt +2 -0
app.py CHANGED
@@ -1,7 +1,22 @@
1
  import gradio as gr
 
 
 
2
 
3
- def greet(name):
4
- return "Hello " + name + "!!"
5
 
6
- iface = gr.Interface(fn=greet, inputs="text", outputs="text")
7
- iface.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
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