micole66 commited on
Commit
60cb125
1 Parent(s): a2a3c2b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -12
app.py CHANGED
@@ -1,16 +1,16 @@
1
  import gradio as gr
2
- from transformers import pipeline
3
 
4
- model = pipeline("text-classification", model="xlm-roberta-large")
 
5
 
6
- def decision_making(option1, option2):
7
- options = [option1, option2]
8
- result = model(options, return_all_scores=True)
9
- if result[0]['score'] > result[1]['score']:
10
- return f"The AI chooses {option1}."
11
- else:
12
- return f"The AI chooses {option2}."
13
 
14
- iface = gr.Interface(fn=decision_making, inputs=["text", "text"], outputs="text", title="Decision Making with XLM-RoBERTa-Large",
15
- description="Enter two options and the AI will choose one.")
16
- iface.launch()
 
 
1
  import gradio as gr
2
+ import transformers
3
 
4
+ tokenizer = transformers.AutoTokenizer.from_pretrained("xlm-roberta-large")
5
+ model = transformers.AutoModelForSequenceClassification.from_pretrained("xlm-roberta-large", num_labels=2)
6
 
7
+ def predict(first_option, second_option):
8
+ input_ids = tokenizer.encode(first_option, second_option, return_tensors="pt", truncation=True, padding=True)
9
+ output = model(input_ids)[0]
10
+ result = torch.argmax(output)
11
+ return first_option if result == 0 else second_option
 
 
12
 
13
+ inputs = [gr.inputs.Textbox(label="Option 1"), gr.inputs.Textbox(label="Option 2")]
14
+ output = gr.outputs.Textbox(label="Chosen Option")
15
+ interface = gr.Interface(fn=predict, inputs=inputs, outputs=output, title="Decision Making with XLM-Roberta-Large", description="Input your two options and let XLM-Roberta-Large choose one.")
16
+ interface.launch()