Spaces:
Running
Running
Upload 4 files
Browse files- app.py +15 -6
- config.json +1 -3
app.py
CHANGED
|
@@ -27,7 +27,7 @@ DEFAULT_CONFIG = {
|
|
| 27 |
'model': 'google/gemma-3-27b-it',
|
| 28 |
'api_key_var': 'API_KEY',
|
| 29 |
'theme': 'Default',
|
| 30 |
-
'grounding_urls': [
|
| 31 |
'enable_dynamic_urls': True,
|
| 32 |
'enable_file_upload': True,
|
| 33 |
'examples': ['Ciao! Come stai oggi?', 'Mi piace giocare a calcio. E tu?', 'Cosa mangi di solito a colazione?', 'A che ora ti svegli la mattina?', 'Qual è il tuo sport preferito?'],
|
|
@@ -478,8 +478,11 @@ Get your API key at: https://openrouter.ai/keys"""
|
|
| 478 |
)
|
| 479 |
|
| 480 |
if response.status_code == 200:
|
| 481 |
-
|
| 482 |
-
|
|
|
|
|
|
|
|
|
|
| 483 |
|
| 484 |
# Add file notification if files were uploaded
|
| 485 |
if file_notification:
|
|
@@ -487,8 +490,11 @@ Get your API key at: https://openrouter.ai/keys"""
|
|
| 487 |
|
| 488 |
return ai_response
|
| 489 |
else:
|
| 490 |
-
|
| 491 |
-
|
|
|
|
|
|
|
|
|
|
| 492 |
return f"❌ API Error ({response.status_code}): {error_message}"
|
| 493 |
|
| 494 |
except requests.exceptions.Timeout:
|
|
@@ -588,7 +594,10 @@ def generate_tts(text: str, max_retries: int = 2) -> Tuple[Optional[Tuple[int, n
|
|
| 588 |
return None, "⏳ Model is loading, please try again in a moment"
|
| 589 |
|
| 590 |
else:
|
| 591 |
-
|
|
|
|
|
|
|
|
|
|
| 592 |
return None, f"❌ API Error ({response.status_code}): {error_msg}"
|
| 593 |
|
| 594 |
except requests.exceptions.Timeout:
|
|
|
|
| 27 |
'model': 'google/gemma-3-27b-it',
|
| 28 |
'api_key_var': 'API_KEY',
|
| 29 |
'theme': 'Default',
|
| 30 |
+
'grounding_urls': [],
|
| 31 |
'enable_dynamic_urls': True,
|
| 32 |
'enable_file_upload': True,
|
| 33 |
'examples': ['Ciao! Come stai oggi?', 'Mi piace giocare a calcio. E tu?', 'Cosa mangi di solito a colazione?', 'A che ora ti svegli la mattina?', 'Qual è il tuo sport preferito?'],
|
|
|
|
| 478 |
)
|
| 479 |
|
| 480 |
if response.status_code == 200:
|
| 481 |
+
try:
|
| 482 |
+
result = response.json()
|
| 483 |
+
ai_response = result['choices'][0]['message']['content']
|
| 484 |
+
except (json.JSONDecodeError, KeyError) as e:
|
| 485 |
+
return f"❌ Error parsing API response: {str(e)}"
|
| 486 |
|
| 487 |
# Add file notification if files were uploaded
|
| 488 |
if file_notification:
|
|
|
|
| 490 |
|
| 491 |
return ai_response
|
| 492 |
else:
|
| 493 |
+
try:
|
| 494 |
+
error_data = response.json()
|
| 495 |
+
error_message = error_data.get('error', {}).get('message', 'Unknown error')
|
| 496 |
+
except:
|
| 497 |
+
error_message = response.text if response.text else 'Unknown error'
|
| 498 |
return f"❌ API Error ({response.status_code}): {error_message}"
|
| 499 |
|
| 500 |
except requests.exceptions.Timeout:
|
|
|
|
| 594 |
return None, "⏳ Model is loading, please try again in a moment"
|
| 595 |
|
| 596 |
else:
|
| 597 |
+
try:
|
| 598 |
+
error_msg = response.json().get('error', 'Unknown error')
|
| 599 |
+
except:
|
| 600 |
+
error_msg = response.text if response.text else 'Unknown error'
|
| 601 |
return None, f"❌ API Error ({response.status_code}): {error_msg}"
|
| 602 |
|
| 603 |
except requests.exceptions.Timeout:
|
config.json
CHANGED
|
@@ -15,9 +15,7 @@
|
|
| 15 |
"A che ora ti svegli la mattina?",
|
| 16 |
"Qual \u00e8 il tuo sport preferito?"
|
| 17 |
],
|
| 18 |
-
"grounding_urls": [
|
| 19 |
-
"https://www.pnac.org/wp-content/uploads/Italian-Study-Guide.pdf"
|
| 20 |
-
],
|
| 21 |
"enable_dynamic_urls": true,
|
| 22 |
"enable_file_upload": true,
|
| 23 |
"enable_tts": true,
|
|
|
|
| 15 |
"A che ora ti svegli la mattina?",
|
| 16 |
"Qual \u00e8 il tuo sport preferito?"
|
| 17 |
],
|
| 18 |
+
"grounding_urls": [],
|
|
|
|
|
|
|
| 19 |
"enable_dynamic_urls": true,
|
| 20 |
"enable_file_upload": true,
|
| 21 |
"enable_tts": true,
|