HA commited on
Commit
548de8d
·
1 Parent(s): 5d24be6

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -0
app.py ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import AutoTokenizer, pipeline
3
+
4
+ # Load the tokenizer
5
+ # model_checkpoint = "roberta-large"
6
+ # tokenizer = AutoTokenizer.from_pretrained(model_checkpoint)
7
+
8
+ model_checkpoint = "tyutfyu/roberta-large-2"
9
+
10
+
11
+ # Load the text classification pipeline
12
+ pipe = pipeline("text-classification", model=model_checkpoint)
13
+
14
+ def classify_text(text, question):
15
+ result = pipe(question, text)
16
+ if result[0]['label'] == 'LABEL_0':
17
+ result[0]['label'] = 'yes'
18
+ elif result[0]['label'] == 'LABEL_1':
19
+ result[0]['label'] = 'no'
20
+ return result[0]['label'], result[0]['score']
21
+
22
+ # Create the Gradio interface
23
+ iface = gr.Interface(
24
+ fn=classify_text,
25
+ inputs=["text", "text"],
26
+ outputs=["text", "number"],
27
+ layout="vertical",
28
+ live=True,
29
+ title="Get yes/No answer for your medical question",
30
+ description="Predict if a statement is true or false."
31
+ )
32
+
33
+ # Launch the Gradio interface
34
+ iface.launch()