Actor_game / app.py
muhnatha's picture
Update app.py
c40ebdf verified
raw
history blame
1.45 kB
from transformers import pipeline
import gradio as gr
import random
def actor_game(text, emotion):
pred_emotion = pipe(text)
if pred_emotion[0]['label'] == emotion:
return "YOU WON", emotion, pred_emotion[0]['label']
else:
return "YOU LOSE", emotion, pred_emotion[0]['label']
pipe = pipeline("text-classification", model="muhnatha/distilbert-base-uncased-game")
question = {
"sadness": "Be a student who just had a bad grade",
"joy": "Be a football player who just won the world cup",
"love": "Be a teenager who has a crush but she can only talk to her friend",
"anger": "Be a student who angry because he was bullied",
"fear": "Be a grandpa who tries to run away because there is an alien in his farm",
"surprise": "Be a child who just got a birthday surprise"
}
task = random.choice(list(question.items()))
def play(click_count=0):
if click_count == 0:
task = random.choice(list(question.items()))
with gr.Blocks() as demo:
gr.Markdown(
"""
# Be an Actor!
Type your dialog.
"""
)
inp_dialog = gr.Textbox(placeholder=task[1])
inp_emotion = gr.Textbox(value=task[0], visible=False)
out = gr.Textbox()
inp_dialog.change(actor_game, [inp_dialog, inp_emotion], out)
reset_button = gr.Button()
reset_button.click(lambda: play(click_count + 1))
demo.launch()
play()