Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -6,11 +6,12 @@ import io
|
|
6 |
import google.generativeai as genai
|
7 |
|
8 |
# --- API Keys (Set as environment variables for security!) ---
|
9 |
-
|
10 |
elevenlabs_api_key = os.environ.get("ELEVENLABS_API_KEY")
|
11 |
|
12 |
#elevenlabs.set_api_key(elevenlabs_api_key)
|
13 |
elevenlabs.API_KEY = elevenlabs_api_key
|
|
|
14 |
|
15 |
# --- ElevenLabs Voice ---
|
16 |
voice = "Bella" # Choose a voice from ElevenLabs
|
@@ -31,13 +32,25 @@ model = genai.GenerativeModel('gemini-pro', generate_response_clause=genai.types
|
|
31 |
def generate_question(difficulty):
|
32 |
"""Generates a Arabic question based on difficulty using Gemini."""
|
33 |
prompt = f"Generate a simple {target_language} question for a language learner at difficulty level {difficulty}. Just the question, no extra text."
|
34 |
-
response =
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
return response.text.strip()
|
36 |
|
37 |
def evaluate_answer(question, answer):
|
38 |
"""Evaluates the user's answer using Gemini."""
|
39 |
prompt = f"You are a Arabic language tutor. Evaluate the following answer to the question: '{question}'. Answer: '{answer}'. Provide feedback on grammar, vocabulary, and fluency. Keep the feedback concise (under 50 words). Also, give a score from 1-5 (1 being very poor, 5 being excellent)."
|
40 |
-
response = model.generate_content(prompt)
|
|
|
|
|
|
|
|
|
|
|
|
|
41 |
return response.text.strip()
|
42 |
|
43 |
def text_to_speech(text, voice):
|
|
|
6 |
import google.generativeai as genai
|
7 |
|
8 |
# --- API Keys (Set as environment variables for security!) ---
|
9 |
+
genai_api_key = os.environ.get("GOOGLE_API_KEY") # Gemini API Key
|
10 |
elevenlabs_api_key = os.environ.get("ELEVENLABS_API_KEY")
|
11 |
|
12 |
#elevenlabs.set_api_key(elevenlabs_api_key)
|
13 |
elevenlabs.API_KEY = elevenlabs_api_key
|
14 |
+
client = genai.Client(api_key=genai_api_key)
|
15 |
|
16 |
# --- ElevenLabs Voice ---
|
17 |
voice = "Bella" # Choose a voice from ElevenLabs
|
|
|
32 |
def generate_question(difficulty):
|
33 |
"""Generates a Arabic question based on difficulty using Gemini."""
|
34 |
prompt = f"Generate a simple {target_language} question for a language learner at difficulty level {difficulty}. Just the question, no extra text."
|
35 |
+
response = client.models.generate_content(
|
36 |
+
model="gemini-2.0-flash",
|
37 |
+
contents=prompt,
|
38 |
+
config=types.GenerateContentConfig(temperature=0.95)
|
39 |
+
)
|
40 |
+
|
41 |
+
#response = model.generate_content(prompt)
|
42 |
return response.text.strip()
|
43 |
|
44 |
def evaluate_answer(question, answer):
|
45 |
"""Evaluates the user's answer using Gemini."""
|
46 |
prompt = f"You are a Arabic language tutor. Evaluate the following answer to the question: '{question}'. Answer: '{answer}'. Provide feedback on grammar, vocabulary, and fluency. Keep the feedback concise (under 50 words). Also, give a score from 1-5 (1 being very poor, 5 being excellent)."
|
47 |
+
#response = model.generate_content(prompt)
|
48 |
+
response = client.models.generate_content(
|
49 |
+
model="gemini-2.0-flash",
|
50 |
+
contents=prompt,
|
51 |
+
config=types.GenerateContentConfig(temperature=0.1)
|
52 |
+
)
|
53 |
+
|
54 |
return response.text.strip()
|
55 |
|
56 |
def text_to_speech(text, voice):
|