muhnatha commited on
Commit
ccdac2b
·
verified ·
1 Parent(s): c40ebdf

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -36
app.py CHANGED
@@ -1,44 +1,22 @@
1
  from transformers import pipeline
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 = {
15
- "sadness": "Be a student who just had a bad grade",
16
- "joy": "Be a football player who just won the world cup",
17
- "love": "Be a teenager who has a crush but she can only talk to her friend",
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()
 
1
  from transformers import pipeline
2
  import gradio as gr
 
3
 
4
+ pipe = pipeline("text-classification", model="muhnatha/distilbert-base-uncased-game")
5
+
6
+ def actor_game(emotion, text):
7
  pred_emotion = pipe(text)
8
  if pred_emotion[0]['label'] == emotion:
9
+ return "YOU WON",emotion,pred_emotion[0]['label']
10
  else:
11
+ return "YOU LOSE",emotion,pred_emotion[0]['label']
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
 
13
+ iface = gr.Interface(
14
+ fn=actor_game,
15
+ inputs=[gr.Textbox(label="What emotion do you want to train?",placeholder = "joy, sadness, fear, surprise, love, anger"),
16
+ gr.Textbox(label="your dialog")],
17
+ outputs=[gr.Textbox(label="Result"),gr.Textbox(label="Expected"),gr.Textbox(label="your emotion")],
18
+ title="Be an Actor",
19
+ description="Type your dialog",
20
+ )
 
 
 
 
 
 
21
 
22
+ iface.launch()