Update app.py
Browse files
app.py
CHANGED
@@ -17,41 +17,74 @@ if not hf_token:
|
|
17 |
client = InferenceClient("Qwen/Qwen2.5-72B-Instruct", token=hf_token)
|
18 |
|
19 |
TOPIC_EXAMPLES = {
|
20 |
-
"Daily Life":
|
21 |
-
"
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
"
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
"
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
"
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
"
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
"
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
55 |
}
|
56 |
|
57 |
MAX_HISTORY_LENGTH = 20
|
@@ -60,8 +93,8 @@ MAX_TOKENS = 1024
|
|
60 |
TEMPERATURE = 0.7
|
61 |
TOP_P = 0.95
|
62 |
|
63 |
-
def get_examples_for_topic(topic):
|
64 |
-
return TOPIC_EXAMPLES.get(topic,
|
65 |
|
66 |
def get_conversation_prompt():
|
67 |
return """You are JoJo, a friendly and supportive AI who helps people practice speaking English through fun, casual conversation.
|
@@ -132,7 +165,7 @@ with gr.Blocks(theme=gr.themes.Soft(), css=custom_css) as demo:
|
|
132 |
gr.Markdown("""
|
133 |
# 🐰 JoJo - Your Speaking Buddy
|
134 |
**Practice English by having natural conversations with JoJo.**
|
135 |
-
Choose a topic and start chatting. JoJo will keep the conversation going and gently correct you if needed.
|
136 |
""")
|
137 |
|
138 |
avatar = get_avatar_url()
|
@@ -165,14 +198,20 @@ with gr.Blocks(theme=gr.themes.Soft(), css=custom_css) as demo:
|
|
165 |
value="Daily Life"
|
166 |
)
|
167 |
|
|
|
|
|
|
|
|
|
|
|
|
|
168 |
gr.Markdown("## Quick Starters")
|
169 |
starter_btn1 = gr.Button("Starter 1", scale=1, min_width=250, elem_classes="compact-btn")
|
170 |
starter_btn2 = gr.Button("Starter 2", scale=1, min_width=250, elem_classes="compact-btn")
|
171 |
starter_btn3 = gr.Button("Starter 3", scale=1, min_width=250, elem_classes="compact-btn")
|
172 |
starter_buttons = [starter_btn1, starter_btn2, starter_btn3]
|
173 |
|
174 |
-
def update_starters(selected_topic):
|
175 |
-
examples = get_examples_for_topic(selected_topic)
|
176 |
results = [examples[i] if i < len(examples) else "" for i in range(3)]
|
177 |
return tuple(results)
|
178 |
|
@@ -188,15 +227,16 @@ with gr.Blocks(theme=gr.themes.Soft(), css=custom_css) as demo:
|
|
188 |
for btn in starter_buttons:
|
189 |
btn.click(fn=use_starter, inputs=[btn, chatbot, topic, memory_flag], outputs=[msg, chatbot], queue=True)
|
190 |
|
191 |
-
topic.change(fn=update_starters, inputs=[topic], outputs=starter_buttons)
|
|
|
192 |
|
193 |
msg.submit(fn=respond, inputs=[msg, chatbot, topic, memory_flag], outputs=[msg, chatbot])
|
194 |
submit.click(fn=respond, inputs=[msg, chatbot, topic, memory_flag], outputs=[msg, chatbot])
|
195 |
clear.click(lambda: [], None, chatbot, queue=False)
|
196 |
clear.click(lambda: "", None, msg, queue=False)
|
197 |
|
198 |
-
default_starters = get_examples_for_topic("Daily Life")
|
199 |
demo.load(fn=lambda: tuple(default_starters[:3]), outputs=starter_buttons, queue=False)
|
200 |
|
201 |
if __name__ == "__main__":
|
202 |
-
demo.launch(server_name="0.0.0.0", server_port=7860)
|
|
|
17 |
client = InferenceClient("Qwen/Qwen2.5-72B-Instruct", token=hf_token)
|
18 |
|
19 |
TOPIC_EXAMPLES = {
|
20 |
+
"Daily Life": {
|
21 |
+
"beginner": [
|
22 |
+
"What time do you wake up?",
|
23 |
+
"Do you go to school or work?",
|
24 |
+
"What do you eat for breakfast?"
|
25 |
+
],
|
26 |
+
"intermediate": [
|
27 |
+
"What do you usually do after work?",
|
28 |
+
"Do you like cooking? What’s your favorite dish?",
|
29 |
+
"Tell me about your morning routine."
|
30 |
+
],
|
31 |
+
"advanced": [
|
32 |
+
"How do you balance personal and professional responsibilities?",
|
33 |
+
"What does a productive day look like for you?",
|
34 |
+
"How has your daily routine changed over the years?"
|
35 |
+
]
|
36 |
+
},
|
37 |
+
"Travel": {
|
38 |
+
"beginner": [
|
39 |
+
"Do you like to travel?",
|
40 |
+
"Have you been to another city?",
|
41 |
+
"Do you like airplanes?"
|
42 |
+
],
|
43 |
+
"intermediate": [
|
44 |
+
"Have you ever been to another country?",
|
45 |
+
"What's your dream vacation?",
|
46 |
+
"What do you like to pack in your suitcase?"
|
47 |
+
],
|
48 |
+
"advanced": [
|
49 |
+
"How has travel influenced your worldview?",
|
50 |
+
"What do you think makes a destination culturally significant?",
|
51 |
+
"Describe your most challenging travel experience."
|
52 |
+
]
|
53 |
+
},
|
54 |
+
"Food": {
|
55 |
+
"beginner": [
|
56 |
+
"Do you like fruit?",
|
57 |
+
"What’s your favorite snack?",
|
58 |
+
"Do you drink tea or coffee?"
|
59 |
+
],
|
60 |
+
"intermediate": [
|
61 |
+
"What's your favorite food?",
|
62 |
+
"Can you describe how to cook a simple dish?",
|
63 |
+
"What did you eat today?"
|
64 |
+
],
|
65 |
+
"advanced": [
|
66 |
+
"How do food choices reflect cultural identity?",
|
67 |
+
"What are your thoughts on sustainable eating?",
|
68 |
+
"Describe a memorable meal and why it stood out."
|
69 |
+
]
|
70 |
+
},
|
71 |
+
"Work & School": {
|
72 |
+
"beginner": [
|
73 |
+
"Do you go to school?",
|
74 |
+
"Do you have a job?",
|
75 |
+
"Do you have homework?"
|
76 |
+
],
|
77 |
+
"intermediate": [
|
78 |
+
"What do you do for work or study?",
|
79 |
+
"Describe your typical workday.",
|
80 |
+
"What subjects do you like or dislike?"
|
81 |
+
],
|
82 |
+
"advanced": [
|
83 |
+
"What are the most important skills in your field?",
|
84 |
+
"How do you manage work-life balance?",
|
85 |
+
"Describe a major accomplishment and how you achieved it."
|
86 |
+
]
|
87 |
+
}
|
88 |
}
|
89 |
|
90 |
MAX_HISTORY_LENGTH = 20
|
|
|
93 |
TEMPERATURE = 0.7
|
94 |
TOP_P = 0.95
|
95 |
|
96 |
+
def get_examples_for_topic(topic, difficulty):
|
97 |
+
return TOPIC_EXAMPLES.get(topic, {}).get(difficulty, [])
|
98 |
|
99 |
def get_conversation_prompt():
|
100 |
return """You are JoJo, a friendly and supportive AI who helps people practice speaking English through fun, casual conversation.
|
|
|
165 |
gr.Markdown("""
|
166 |
# 🐰 JoJo - Your Speaking Buddy
|
167 |
**Practice English by having natural conversations with JoJo.**
|
168 |
+
Choose a topic and difficulty, then start chatting. JoJo will keep the conversation going and gently correct you if needed.
|
169 |
""")
|
170 |
|
171 |
avatar = get_avatar_url()
|
|
|
198 |
value="Daily Life"
|
199 |
)
|
200 |
|
201 |
+
difficulty = gr.Dropdown(
|
202 |
+
choices=["beginner", "intermediate", "advanced"],
|
203 |
+
label="Select Difficulty",
|
204 |
+
value="intermediate"
|
205 |
+
)
|
206 |
+
|
207 |
gr.Markdown("## Quick Starters")
|
208 |
starter_btn1 = gr.Button("Starter 1", scale=1, min_width=250, elem_classes="compact-btn")
|
209 |
starter_btn2 = gr.Button("Starter 2", scale=1, min_width=250, elem_classes="compact-btn")
|
210 |
starter_btn3 = gr.Button("Starter 3", scale=1, min_width=250, elem_classes="compact-btn")
|
211 |
starter_buttons = [starter_btn1, starter_btn2, starter_btn3]
|
212 |
|
213 |
+
def update_starters(selected_topic, selected_difficulty):
|
214 |
+
examples = get_examples_for_topic(selected_topic, selected_difficulty)
|
215 |
results = [examples[i] if i < len(examples) else "" for i in range(3)]
|
216 |
return tuple(results)
|
217 |
|
|
|
227 |
for btn in starter_buttons:
|
228 |
btn.click(fn=use_starter, inputs=[btn, chatbot, topic, memory_flag], outputs=[msg, chatbot], queue=True)
|
229 |
|
230 |
+
topic.change(fn=update_starters, inputs=[topic, difficulty], outputs=starter_buttons)
|
231 |
+
difficulty.change(fn=update_starters, inputs=[topic, difficulty], outputs=starter_buttons)
|
232 |
|
233 |
msg.submit(fn=respond, inputs=[msg, chatbot, topic, memory_flag], outputs=[msg, chatbot])
|
234 |
submit.click(fn=respond, inputs=[msg, chatbot, topic, memory_flag], outputs=[msg, chatbot])
|
235 |
clear.click(lambda: [], None, chatbot, queue=False)
|
236 |
clear.click(lambda: "", None, msg, queue=False)
|
237 |
|
238 |
+
default_starters = get_examples_for_topic("Daily Life", "intermediate")
|
239 |
demo.load(fn=lambda: tuple(default_starters[:3]), outputs=starter_buttons, queue=False)
|
240 |
|
241 |
if __name__ == "__main__":
|
242 |
+
demo.launch(server_name="0.0.0.0", server_port=7860)
|