Spaces:
Running
Running
Setup Gradio space
Browse files- .gitignore +2 -0
- app.py +31 -59
- requirements.txt +2 -1
- story.txt +5 -0
.gitignore
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
.venv/
|
2 |
+
.idea/
|
app.py
CHANGED
@@ -1,64 +1,36 @@
|
|
1 |
import gradio as gr
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
):
|
18 |
-
|
19 |
-
|
20 |
-
for
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
for
|
31 |
-
|
32 |
-
|
33 |
-
stream=True,
|
34 |
-
temperature=temperature,
|
35 |
-
top_p=top_p,
|
36 |
-
):
|
37 |
-
token = message.choices[0].delta.content
|
38 |
-
|
39 |
-
response += token
|
40 |
-
yield response
|
41 |
-
|
42 |
-
|
43 |
-
"""
|
44 |
-
For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
|
45 |
-
"""
|
46 |
-
demo = gr.ChatInterface(
|
47 |
-
respond,
|
48 |
-
additional_inputs=[
|
49 |
-
gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
|
50 |
-
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
|
51 |
-
gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
|
52 |
-
gr.Slider(
|
53 |
-
minimum=0.1,
|
54 |
-
maximum=1.0,
|
55 |
-
value=0.95,
|
56 |
-
step=0.05,
|
57 |
-
label="Top-p (nucleus sampling)",
|
58 |
-
),
|
59 |
-
],
|
60 |
)
|
61 |
|
62 |
-
|
63 |
if __name__ == "__main__":
|
64 |
demo.launch()
|
|
|
1 |
import gradio as gr
|
2 |
+
import torch
|
3 |
+
from transformers import AutoModelForSequenceClassification, AutoTokenizer
|
4 |
+
|
5 |
+
CLASSES = {
|
6 |
+
'yes': 0,
|
7 |
+
'irrelevant': 1,
|
8 |
+
'no': 2,
|
9 |
+
}
|
10 |
+
checkpoint_path = "MrPio/TheSeagullStory-nli-deberta-v3-base"
|
11 |
+
model = AutoModelForSequenceClassification.from_pretrained(checkpoint_path)
|
12 |
+
model.eval()
|
13 |
+
tokenizer = AutoTokenizer.from_pretrained(checkpoint_path)
|
14 |
+
story = open('story.txt').read().replace("\n\n", "\n").replace("\n", " ").strip()
|
15 |
+
|
16 |
+
|
17 |
+
def ask(question):
|
18 |
+
inputs = tokenizer(story, question, truncation=True, padding=True)
|
19 |
+
prediction = torch.softmax(model(**inputs), dim=-1).squeeze()
|
20 |
+
return [{c: prediction[i].item() for c, i in CLASSES}]
|
21 |
+
|
22 |
+
|
23 |
+
demo = gr.Interface(
|
24 |
+
ask,
|
25 |
+
inputs=[gr.Textbox(value="", label="Your question, as an affirmative sentence:")],
|
26 |
+
outputs=[gr.Label(label="Answer", num_top_classes=3)],
|
27 |
+
title="The Seagull Story",
|
28 |
+
description="“ Albert and Dave find themselves on the pier. They go to a nearby restaurant where Albert orders seagull meat. The waiter promptly serves Albert the meal. After taking a bite, he realizes something. Albert pulls a gun out of his ruined jacket and shoots himself. ”\n\nWhy did Albert shoot himself?\n\nCan you unravel the truth behind this epilogue by asking only yes/no questions?",
|
29 |
+
article='Please refrain from embarrassing DeBERTa with ridiculous questions.',
|
30 |
+
examples=['Albert shoot himself for a reason',
|
31 |
+
'Dave has a watch on his wrist',
|
32 |
+
'Albert and Dave came to the pier on their own']
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
)
|
34 |
|
|
|
35 |
if __name__ == "__main__":
|
36 |
demo.launch()
|
requirements.txt
CHANGED
@@ -1,3 +1,4 @@
|
|
1 |
huggingface_hub==0.25.2
|
2 |
transformers
|
3 |
-
torch
|
|
|
|
1 |
huggingface_hub==0.25.2
|
2 |
transformers
|
3 |
+
torch
|
4 |
+
gradio
|
story.txt
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
While enjoying a peaceful boat ride, Albert, Dave and Lucy are stranded on a deserted island by a violent storm. They face the challenges of survival in a place far from their original plans.
|
2 |
+
Lucy dies in the shipwreck, leaving Albert and Dave to survive on a desert island with no food or animals. While exploring, Dave discovers Lucy's lifeless body, which causes Dave great grief. He keeps the discovery to himself, fearing that Albert would be devastated if he knew. He pretends that Lucy is still with them, which at first makes Albert believe it.
|
3 |
+
Several days pass and Dave and Albert struggle to survive without food. Dave has no choice but to eat and feed Albert with some of Lucy's remains. He does not tell Albert the truth about their food source. He assures Albert that they eat seagull meat. Albert doubts his words but decides to trust him for now.
|
4 |
+
A passing sailor sees Albert and Dave and rescues them from the island. The sailor is genuinely concerned about them. On the boat, Albert becomes increasingly worried about his wife, Lucy, and questions Dave's lies about her whereabouts. He believes that the seagull meat Dave made him eat on the island was Lucy's body, and insists on going to a restaurant to taste the real seagull meat to uncover the truth. At Albert's insistence and against Dave's will, the sailor takes them to a nearby pier.
|
5 |
+
Albert and Dave find themselves on the pier, sad and shocked. Still unaware of Lucy's fate, Albert discusses it with Dave. They go to a nearby restaurant where Albert orders seagull meat, as he had planned. The waiter promptly serves Albert the meal. The food is perfectly good and edible. After taking a bite, he realizes that what he ate on the island was not seagull meat, but Lucy's corpse. He does what Dave suspected. To the surprise of the other people in the restaurant, but not to Dave, Albert pulls a gun out of his ruined jacket and shoots himself.
|