Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,16 +1,16 @@
|
|
1 |
import gradio as gr
|
2 |
-
|
3 |
|
4 |
-
|
|
|
5 |
|
6 |
-
def
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
else:
|
12 |
-
return f"The AI chooses {option2}."
|
13 |
|
14 |
-
|
15 |
-
|
16 |
-
|
|
|
|
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()
|