Spaces:
Sleeping
Sleeping
import numpy as np | |
import gradio as gr | |
import tensorflow as tf | |
from transformers import TFAutoModelForSequenceClassification, AutoTokenizer | |
checkpoint="manuu01/DeBERTa-SeagullStory" | |
tokenizer = AutoTokenizer.from_pretrained(checkpoint) | |
model=TFAutoModelForSequenceClassification.from_pretrained(checkpoint,from_pt=True,dtype=tf.float16) | |
answers=['Yes',"Doesn't matter","No"] | |
f=open("Questions.txt","a") | |
title = "The Seagull story" | |
description = """ | |
Albert and Dave are at a pier. They go to a restaurant. Albert orders seagull. He takes a bite, then he kills himself.\n | |
This is the final part of a story. It does not make sense at first, but in the end you can be sure it will actually make sense.\n | |
You can ask boolean questions to which you will receive one of the following answers:\n | |
"Yes" if it is true\n | |
"No" if it is not true\n | |
"Doesn't matter" if what you're asking is not important to understand the whole story.\n\n | |
Example: Bob liked the restaurant\n | |
--Answer: Doesn't matter\n | |
Bob shot himself because he did not have money to pay\n | |
--Answer: No | |
""" | |
def generate_tone(index,question): | |
passages=[ | |
""" | |
Albert Dave and lucy are friends. they are completely normal people. Albert and lucy are happily married. Albert and lucy are | |
loyal and really love each other, their love is true. Albert loves lucy. lucy loves Albert. Albert Dave and lucy are middle aged. | |
Albert is blind. Albert is not religious. | |
the story is set in the early 900's. the story is completely plausible and does not involve anything not realistic. | |
""".replace("\n",""), | |
""" | |
A kind sailor saved Albert and Dave from an island and brought them to a pier with his boat. Now, they are sad and shocked. | |
Albert does not know lucy is dead, Dave knows Lucy is dead. They go to a restaurant. Albert orders seagull meat. | |
The waiter brings Albert the seagull meat. Everything is ordinary. The seagull meat is perfectly fine and edible. | |
After Albert takes a bite, he realizes he had never eaten seagull meat before and because of that Albert kills himself. | |
Dave knew Albert would suicide, so he is not surpirsed. Other people at the restaurant were surprised. | |
Albert and Dave were exhausted. Albert and Dave had discussions. Albert wanted to go to the restaurant | |
in order to eat seagull, Albert had this plan when he was on the island and nothing that happened changed Albert's mind. | |
""".replace("\n",""), | |
""" | |
Albert Dave and lucy are having fun. they did not have any argument. | |
what happened was not upon them. there is a storm and the boat is wrecked. Albert, Dave, lucy cast away on an island. | |
""".replace("\n",""), | |
""" | |
lucy dies in the shipwreck. Albert and Dave manage to survive. they are alone on the island. there is no one else on the island. | |
there are not dangerous animals. Albert and Dave do not have to fight to survive. there is no one else on the island. | |
there is not much food.they resort to unconvential food sources. they did not have to fight. Dave finds lucy's corpse. | |
they manage to survive.Dave is compelled to eat lucy. Dave does not want to eat lucy. Dave eats lucy. Albert also eats lucy. | |
because Albert is blind, Albert does not know he is eating lucy. Dave knows he is eating lucy. Dave revolts while eating lucy. | |
Albert does not revolt while eating lucy. Dave tells Albert he is eating seagull. Albert thinks he is eating seagull. | |
Albert is suspicious. there is a sailor passing by. the sailor saves Albert and Dave and brings them to a pier. | |
the sailor is a good man. the sailor does not have ill intentions. Albert and Dave are grateful to the sailor. | |
Albert does not know lucy is dead. Dave knows lucy is dead. | |
""".replace("\n","") | |
] | |
inputs=tokenizer(passages[index],question, return_tensors="tf") | |
response=(model(**inputs).logits) | |
return model.config.id2label[np.argmax(response)] | |
passages=["General","Pier","Boat","Island"] | |
gr.Interface( | |
generate_tone, | |
[ | |
gr.Dropdown(passages, type="index", value="Pier"), | |
gr.Textbox(type="text", label="enter your question"), | |
], | |
"text", | |
title=title, | |
description=description, | |
).launch() |