File size: 1,051 Bytes
b61d174
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
from transformers import pipeline
import gradio as gr
import random

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 actor_game(text, emotion):
    pred_emotion = pipe(text)
    if pred_emotion[0]['label'] == emotion:
        return "YOU WON"
    else:
        return "YOU LOSE"

iface = gr.Interface(
    fn=actor_game,
    inputs=[gr.Textbox(label="Your dialog"), 
            gr.Textbox(task[0],visible=False)],
    outputs=[gr.Textbox(label=task[1])],
    title="Be an Actor",
    description="Type your dialog",
)

iface.launch()