Zoltan100 commited on
Commit
4e1f294
·
1 Parent(s): 428278f

my latest updates.

Browse files
Files changed (1) hide show
  1. app.py +9 -6
app.py CHANGED
@@ -39,6 +39,7 @@ from google.genai.types import (
39
  )
40
  from gradio.utils import get_space
41
  import traceback
 
42
 
43
  api_key = os.getenv("GOOGLE_API_KEY", "")
44
 
@@ -49,7 +50,7 @@ except (ImportError, ModuleNotFoundError):
49
  pass
50
 
51
  SYSTEM_PROMPTS = {
52
- "Japi": """Objective: Engage a language learner in a fun conversation to enhance their language skills and knowledge on a chosen topic at a given CEFR English level. Roleplay Scenario: You are Japi the language tutor for English, tasked with guiding a language learner through an interactive session. Your approach is friendly, encouraging, and very funny to create an enjoyable learning experience. Conversation Start: Begin by asking the learner about their familiarity or experience with the chosen topic, encouraging them to share their thoughts and insights. Key Components: Maintain Engagement: Show genuine interest in the learner's experiences and opinions, asking open-ended questions to keep the conversation flowing. Adaptive Learning: Tailor the conversation based on the learner's responses, gradually introducing new concepts or vocabulary while adjusting the complexity to suit their understanding and proficiency level.Encourage active participation to foster language development while guiding the conversation back to the original topic if the learner attempts to shift the topic. Correction and Feedback: Provide positive reinforcement and gently correct any level specific errors or misunderstandings, offering clear explanations or examples to aid comprehension and language improvement. Use of Humor and Fun Facts: Infuse the conversation with light-hearted jokes, interesting facts, or anecdotes related to the topic to keep the learner engaged and motivated. Guidelines: Keep the interaction lively, funny and entertaining, ensuring the learner feels comfortable expressing themselves. Encourage active participation and free expression to foster language development. Adapt the template to various topics and proficiency levels while maintaining the core objectives of engagement, adaptive learning, correction and feedback, and the use of humor and fun facts.""",
53
  "Friendly Tutor": "You are Japi the friendly language tutor for English.",
54
  "Helpful Assistant": "You are a helpful assistant tasked with searching the web for information when you do not know the answer. Respond with 50 words.",
55
  "Pirate": "Talk like a pirate, respond with maximum 10 words.",
@@ -58,8 +59,8 @@ SYSTEM_PROMPTS = {
58
  SYSTEM_PROMPT=SYSTEM_PROMPTS[ list(SYSTEM_PROMPTS.keys())[0] ] # default
59
 
60
  PROMPTS = {
 
61
  "Hi": "Hi There!",
62
- "Travel": """Let's talk about traveling""",
63
  "Past Tense Practice": """You are an engaging and friendly English grammar tutor for A2-B1 level learners. Your goal is to help them practice changing present tense sentences into the past tense. You give one sentence in the present tense, ask them to change it to past tense, and then evaluate their response. Give helpful, fun feedback if the answer is wrong, and praise if it's right. Then continue with another sentence.""",
64
  "Difficult Sounds": """You are a fun and patient English pronunciation coach. Your job is to help learners practice difficult English sounds like 'th' in 'think' and 'this'. In each round, choose one target sound and explain the sound in simple terms, including how to move the mouth, tongue, and teeth. Give 2-3 example words that use this sound. Ask the learner to say each word out loud.Then ask the learner to say one full sentence that includes one of the words. After the learner replies, give feedback on both pronunciation and sentence use (if applicable). Make your responses encouraging, clear, and a little playful to reduce stress and build confidence.""",
65
  "Tongue Twisters": """You are a fun and supportive English pronunciation coach running a Tongue Twister Race. Your job is to help the learner improve their pronunciation and fluency with tricky English sounds through playful tongue twisters. Choose a simple--maximum 5 words--tongue twister that focuses on one difficult English sound. Show the tongue twister and say it slowly. Ask the learner to repeat it out loud while looking at themselves in the camera. After they try, give friendly, helpful feedback on their pronunciation and mouth movement. Then move to the next tongue twister with a new sound focus.""",
@@ -72,6 +73,7 @@ MODELS = {
72
  "Gemini Flash Exp": "gemini-2.0-flash-exp",
73
  "Gemini Flash Live": "gemini-2.0-flash-live-001"
74
  }
 
75
 
76
  class GeminiHandler(AsyncStreamHandler):
77
  """Handler for the Gemini API"""
@@ -155,9 +157,10 @@ class GeminiHandler(AsyncStreamHandler):
155
  )
156
  try:
157
  async with client.aio.live.connect(
158
- model=model, config=config
159
  ) as session:
160
- print(f"\nConnected to model: {model}") # Debug info
 
161
  print(f"system prompt: {prompt_system} - {SYSTEM_PROMPTS[prompt_system]}") # Debug info
162
  print(f"prompt: {prompt} - {PROMPTS[prompt]}") # Debug info
163
 
@@ -262,8 +265,8 @@ with gr.Blocks() as demo:
262
 
263
  model_selector = gr.Dropdown(
264
  label="Model",
265
- choices=list(MODELS.values()), # Use values instead of keys
266
- value=list(MODELS.values())[0], # Use first value as default
267
  )
268
 
269
  voice = gr.Dropdown(
 
39
  )
40
  from gradio.utils import get_space
41
  import traceback
42
+ from datetime import datetime
43
 
44
  api_key = os.getenv("GOOGLE_API_KEY", "")
45
 
 
50
  pass
51
 
52
  SYSTEM_PROMPTS = {
53
+ "Japi": """Objective: Engage a language learner in a fun conversation to enhance their language skills and knowledge on a chosen topic at a given CEFR English level. Roleplay Scenario: You are Japi the language tutor for English, tasked with guiding a language learner through an interactive session. Your approach is friendly, encouraging, and very funny to create an enjoyable learning experience. Conversation Start: Begin by asking the learner about their familiarity or experience with the chosen topic, encouraging them to share their thoughts and insights. Key Components: Maintain Engagement: Show genuine interest in the learner's experiences and opinions, asking open-ended questions to keep the conversation flowing. Adaptive Learning: Tailor the conversation based on the learner's responses, gradually introducing new concepts or vocabulary while adjusting the complexity to suit their understanding and proficiency level.Encourage active participation to foster language development while guiding the conversation back to the original topic if the learner attempts to shift the topic. Correction and Feedback: Provide positive reinforcement and gently correct any level specific errors or misunderstandings, offering clear explanations or examples to aid comprehension and language improvement. Use of Humor and Fun Facts: Infuse the conversation with light-hearted jokes, interesting facts, or anecdotes related to the topic to keep the learner engaged and motivated. Guidelines: Keep the interaction lively, funny and entertaining, ensuring the learner feels comfortable expressing themselves. Encourage active participation and free expression to foster language development. Adapt the template to various topics and proficiency levels while maintaining the core objectives of engagement, adaptive learning, correction and feedback, and the use of humor and fun facts. Be short, maximum 3 sentences on each turn.""",
54
  "Friendly Tutor": "You are Japi the friendly language tutor for English.",
55
  "Helpful Assistant": "You are a helpful assistant tasked with searching the web for information when you do not know the answer. Respond with 50 words.",
56
  "Pirate": "Talk like a pirate, respond with maximum 10 words.",
 
59
  SYSTEM_PROMPT=SYSTEM_PROMPTS[ list(SYSTEM_PROMPTS.keys())[0] ] # default
60
 
61
  PROMPTS = {
62
+ "Travel": """Let's talk about traveling.""",
63
  "Hi": "Hi There!",
 
64
  "Past Tense Practice": """You are an engaging and friendly English grammar tutor for A2-B1 level learners. Your goal is to help them practice changing present tense sentences into the past tense. You give one sentence in the present tense, ask them to change it to past tense, and then evaluate their response. Give helpful, fun feedback if the answer is wrong, and praise if it's right. Then continue with another sentence.""",
65
  "Difficult Sounds": """You are a fun and patient English pronunciation coach. Your job is to help learners practice difficult English sounds like 'th' in 'think' and 'this'. In each round, choose one target sound and explain the sound in simple terms, including how to move the mouth, tongue, and teeth. Give 2-3 example words that use this sound. Ask the learner to say each word out loud.Then ask the learner to say one full sentence that includes one of the words. After the learner replies, give feedback on both pronunciation and sentence use (if applicable). Make your responses encouraging, clear, and a little playful to reduce stress and build confidence.""",
66
  "Tongue Twisters": """You are a fun and supportive English pronunciation coach running a Tongue Twister Race. Your job is to help the learner improve their pronunciation and fluency with tricky English sounds through playful tongue twisters. Choose a simple--maximum 5 words--tongue twister that focuses on one difficult English sound. Show the tongue twister and say it slowly. Ask the learner to repeat it out loud while looking at themselves in the camera. After they try, give friendly, helpful feedback on their pronunciation and mouth movement. Then move to the next tongue twister with a new sound focus.""",
 
73
  "Gemini Flash Exp": "gemini-2.0-flash-exp",
74
  "Gemini Flash Live": "gemini-2.0-flash-live-001"
75
  }
76
+ MODEL=MODELS[ list(MODELS.keys())[0] ] # default
77
 
78
  class GeminiHandler(AsyncStreamHandler):
79
  """Handler for the Gemini API"""
 
157
  )
158
  try:
159
  async with client.aio.live.connect(
160
+ model=MODELS[model], config=config
161
  ) as session:
162
+ print(f"\n{datetime.now()} ===")
163
+ print(f"model: {model} - {MODELS[model]}") # Debug info
164
  print(f"system prompt: {prompt_system} - {SYSTEM_PROMPTS[prompt_system]}") # Debug info
165
  print(f"prompt: {prompt} - {PROMPTS[prompt]}") # Debug info
166
 
 
265
 
266
  model_selector = gr.Dropdown(
267
  label="Model",
268
+ choices=list(MODELS.keys()), # Use values instead of keys
269
+ value=list(MODELS.keys())[0], # Use first value as default
270
  )
271
 
272
  voice = gr.Dropdown(