Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,6 +2,13 @@ from transformers import pipeline
|
|
| 2 |
import gradio as gr
|
| 3 |
import random
|
| 4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
pipe = pipeline("text-classification", model="muhnatha/distilbert-base-uncased-game")
|
| 6 |
|
| 7 |
question = {
|
|
@@ -11,43 +18,27 @@ question = {
|
|
| 11 |
"anger": "Be a student who angry because he was bullied",
|
| 12 |
"fear": "Be a grandpa who tries to run away because there is an alien in his farm",
|
| 13 |
"surprise": "Be a child who just got a birthday surprise"
|
| 14 |
-
}
|
| 15 |
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
else:
|
| 21 |
-
result = "YOU LOSE"
|
| 22 |
-
if play_again.lower() == "yes":
|
| 23 |
task = random.choice(list(question.items()))
|
| 24 |
-
return result, emotion, pred_emotion[0]['label'], task[1], task[0]
|
| 25 |
-
else:
|
| 26 |
-
return result, emotion, pred_emotion[0]['label'], "Game Over", ""
|
| 27 |
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
],
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
gr.Textbox(label="Next emotion", visible=False)
|
| 43 |
-
],
|
| 44 |
-
title="Be an Actor",
|
| 45 |
-
description="Type your dialog",
|
| 46 |
-
allow_flagging="never"
|
| 47 |
-
)
|
| 48 |
-
iface.launch()
|
| 49 |
-
response = iface.launch()
|
| 50 |
-
if response[2] == "yes": # Check if user wants to play again
|
| 51 |
-
initialize_interface() # Restart the game
|
| 52 |
|
| 53 |
-
|
|
|
|
| 2 |
import gradio as gr
|
| 3 |
import random
|
| 4 |
|
| 5 |
+
def actor_game(text, emotion):
|
| 6 |
+
pred_emotion = pipe(text)
|
| 7 |
+
if pred_emotion[0]['label'] == emotion:
|
| 8 |
+
return "YOU WON", emotion, pred_emotion[0]['label']
|
| 9 |
+
else:
|
| 10 |
+
return "YOU LOSE", emotion, pred_emotion[0]['label']
|
| 11 |
+
|
| 12 |
pipe = pipeline("text-classification", model="muhnatha/distilbert-base-uncased-game")
|
| 13 |
|
| 14 |
question = {
|
|
|
|
| 18 |
"anger": "Be a student who angry because he was bullied",
|
| 19 |
"fear": "Be a grandpa who tries to run away because there is an alien in his farm",
|
| 20 |
"surprise": "Be a child who just got a birthday surprise"
|
| 21 |
+
}
|
| 22 |
|
| 23 |
+
task = random.choice(list(question.items()))
|
| 24 |
+
|
| 25 |
+
def play(click_count=0):
|
| 26 |
+
if click_count == 0:
|
|
|
|
|
|
|
|
|
|
| 27 |
task = random.choice(list(question.items()))
|
|
|
|
|
|
|
|
|
|
| 28 |
|
| 29 |
+
with gr.Blocks() as demo:
|
| 30 |
+
gr.Markdown(
|
| 31 |
+
"""
|
| 32 |
+
# Be an Actor!
|
| 33 |
+
Type your dialog.
|
| 34 |
+
"""
|
| 35 |
+
)
|
| 36 |
+
inp_dialog = gr.Textbox(placeholder=task[1])
|
| 37 |
+
inp_emotion = gr.Textbox(value=task[0], visible=False)
|
| 38 |
+
out = gr.Textbox()
|
| 39 |
+
inp_dialog.change(actor_game, [inp_dialog, inp_emotion], out)
|
| 40 |
+
reset_button = gr.Button()
|
| 41 |
+
reset_button.click(lambda: play(click_count + 1))
|
| 42 |
+
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
|
| 44 |
+
play()
|