Spaces:
Sleeping
Sleeping
Update flask_app.py
Browse files- flask_app.py +1 -32
flask_app.py
CHANGED
|
@@ -143,38 +143,7 @@ def tts_proxy():
|
|
| 143 |
except Exception as e:
|
| 144 |
return jsonify({"error": f"Failed to generate audio via gTTS: {e}"}), 500
|
| 145 |
|
| 146 |
-
|
| 147 |
-
def explain_proxy():
|
| 148 |
-
data = request.get_json()
|
| 149 |
-
model_provider, model_name = data.get('model', 'gemini:gemini-2.5-flash-latest').split(':', 1)
|
| 150 |
-
context_focus = data.get('context_focus', 'General/Social')
|
| 151 |
-
custom_prompt = data.get('custom_prompt', None)
|
| 152 |
-
word = data.get('word', '').strip()
|
| 153 |
-
context = data.get('context', '')
|
| 154 |
-
for_flashcard = data.get('for_flashcard', False)
|
| 155 |
-
|
| 156 |
-
if (model_provider == 'gemini' and not genai_client) or (model_provider == 'groq' and not groq_client):
|
| 157 |
-
return jsonify({"error": f"{model_provider.upper()}_API_KEY not configured."}), 503
|
| 158 |
-
|
| 159 |
-
system_instruction_base = f"You are a professional English tutor. The user's study focus is '{context_focus}'. All your responses must be in ENGLISH."
|
| 160 |
-
try:
|
| 161 |
-
if custom_prompt:
|
| 162 |
-
activity_text = get_ai_text_response(model_provider, model_name, system_instruction_base, custom_prompt)
|
| 163 |
-
return jsonify({"explanation": activity_text})
|
| 164 |
-
|
| 165 |
-
if not word: return jsonify({"error": "No word selected."}), 400
|
| 166 |
-
|
| 167 |
-
if for_flashcard:
|
| 168 |
-
schema = {"type": "object", "properties": {"term": {"type": "string"}, "translation": {"type": "string"}, "context_sentence": {"type": "string"}, "gapped_sentence": {"type": "string"}, "definition": {"type": "string"}}, "required": ["term", "translation", "context_sentence", "gapped_sentence", "definition"]}
|
| 169 |
-
prompt = f"Analyze '{word}' in context: '{context}'. Generate a JSON for a flashcard. The 'gapped_sentence' must replace '{word}' with '______________'."
|
| 170 |
-
return jsonify(get_ai_text_response(model_provider, model_name, system_instruction_base, prompt, json_schema=schema))
|
| 171 |
-
else:
|
| 172 |
-
prompt = f"Analyze '{word}' in context: '{context}'. Provide a one-sentence English explanation, then '---', then the Portuguese translation."
|
| 173 |
-
parts = get_ai_text_response(model_provider, model_name, system_instruction_base, prompt).split('---', 1)
|
| 174 |
-
return jsonify({"explanation": parts[0].strip(), "translation": parts[1].strip() if len(parts) > 1 else 'N/A'})
|
| 175 |
-
except Exception as e:
|
| 176 |
-
print(f"AI ANALYSIS ERROR in /explain-proxy: {e}")
|
| 177 |
-
return jsonify({"error": f"AI analysis failed: {e}"}), 500
|
| 178 |
|
| 179 |
@app.route('/activity-feedback', methods=['POST'])
|
| 180 |
def activity_feedback():
|
|
|
|
| 143 |
except Exception as e:
|
| 144 |
return jsonify({"error": f"Failed to generate audio via gTTS: {e}"}), 500
|
| 145 |
|
| 146 |
+
# Primeira função explain_proxy removida - duplicata
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 147 |
|
| 148 |
@app.route('/activity-feedback', methods=['POST'])
|
| 149 |
def activity_feedback():
|