File size: 1,451 Bytes
88b6f30
 
 
 
c40ebdf
 
 
 
 
 
 
b61d174
 
 
 
 
 
 
 
 
c40ebdf
b61d174
c40ebdf
 
 
 
cb21aac
b61d174
c40ebdf
 
 
 
 
 
 
 
 
 
 
 
 
 
b61d174
c40ebdf
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
34
35
36
37
38
39
40
41
42
43
44
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()