aliabid94 HF staff commited on
Commit
2a53e07
1 Parent(s): fbdd752

Upload folder using huggingface_hub

Browse files
Files changed (3) hide show
  1. README.md +2 -8
  2. api.py +17 -0
  3. run.py +59 -0
README.md CHANGED
@@ -1,12 +1,6 @@
1
  ---
2
  title: Rizz
3
- emoji: 😻
4
- colorFrom: purple
5
- colorTo: purple
6
  sdk: gradio
7
- sdk_version: 4.14.0
8
- app_file: app.py
9
- pinned: false
10
  ---
11
-
12
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
  ---
2
  title: Rizz
3
+ app_file: run.py
 
 
4
  sdk: gradio
5
+ sdk_version: 4.13.0
 
 
6
  ---
 
 
api.py ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import time
2
+
3
+ def generate_scenario(gender):
4
+ time.sleep(1)
5
+ return f"I see a {gender} in a coffee shop."
6
+
7
+ def suggest_next_line(history):
8
+ time.sleep(1)
9
+ return "So.. what do you do for fun?"
10
+
11
+ def generate_response(history):
12
+ time.sleep(1)
13
+ return "Nice to meet you"
14
+
15
+ def transcribe_audio(audio):
16
+ time.sleep(1)
17
+ return "I like your face"
run.py ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import api
2
+ import gradio as gr
3
+
4
+ with gr.Blocks() as demo:
5
+ with gr.Column() as setup_col:
6
+ gr.HTML("<h1 style='text-align: center; margin-top: 1em; font-size: 2em;'>Rizz++</h1>")
7
+ gr.Markdown("Rizz++ simulates conversations you might have when approaching someone you're interested in, helping you develop your skills. \nRandomly generate a scenario involving...")
8
+ with gr.Row():
9
+ approach_girl = gr.Button("Approaching a Girl")
10
+ approach_boy = gr.Button("Approaching a Boy")
11
+ gr.Markdown("...or enter your own scenario:")
12
+ with gr.Group():
13
+ custom_scenario = gr.Textbox(lines=3, label="Scenario", placeholder="There's a cute girl in my boxing class I want to talk to.")
14
+ scenario_btn = gr.Button("Submit Scenario")
15
+
16
+ with gr.Column(visible=False) as convo_col:
17
+ chat = gr.Chatbot()
18
+ recording = gr.Audio(label="Your Line", sources="microphone")
19
+ with gr.Group():
20
+ with gr.Row():
21
+ help_btn = gr.Button("Help Me", scale=0)
22
+ suggestion = gr.Textbox(container=False, placeholder="Stuck? Let Rizz++ suggest your next line!")
23
+
24
+ @gr.on([approach_boy.click, approach_girl.click, scenario_btn.click], outputs=[setup_col, convo_col])
25
+ def start_convo():
26
+ return {
27
+ setup_col: gr.Column(visible=False),
28
+ convo_col: gr.Column(visible=True)
29
+ }
30
+
31
+ scenario = gr.State()
32
+ SCENARIO_LINE = "The scenario is: **{}** \n\n Record your opening line below!"
33
+
34
+ def start_chat(scenario):
35
+ return [[SCENARIO_LINE.format(scenario), None]]
36
+
37
+ approach_boy.click(lambda: api.generate_scenario("boy"), outputs=scenario).then(start_chat, scenario, chat)
38
+ approach_girl.click(lambda: api.generate_scenario("girl"), outputs=scenario).then(start_chat, scenario, chat)
39
+ scenario_btn.click(lambda x: x, custom_scenario, scenario).then(start_chat, scenario, chat)
40
+
41
+
42
+ def transcribe(recording, chat):
43
+ user_message = api.transcribe_audio(recording)
44
+ chat.append([user_message, None])
45
+ return chat
46
+
47
+ def respond(chat):
48
+ response = api.generate_response(chat[1:])
49
+ chat[-1][1] = response
50
+ return chat
51
+
52
+
53
+ recording.stop_recording(transcribe, inputs=[recording, chat], outputs=[chat]
54
+ ).then(respond, inputs=[chat], outputs=[chat]
55
+ ).then(lambda: None, outputs=[recording])
56
+
57
+ help_btn.click(lambda chat: api.suggest_next_line(chat[1:]), inputs=[chat], outputs=[suggestion])
58
+
59
+ demo.launch()