Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -36,17 +36,19 @@ def index():
|
|
36 |
|
37 |
@app.route('/api/francais', methods=['POST','GET'])
|
38 |
def gpt_francais():
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
|
|
|
|
44 |
|
45 |
logging.info(f"Données reçues : sujet='{french_prompt[:50]}', choix='{choix}', style='{style}', deepthink={use_deepthink}")
|
46 |
|
47 |
if not french_prompt:
|
48 |
logging.warning("Sujet vide, retour erreur.")
|
49 |
-
return Response(f"data: {json.dumps({'type': 'error', 'content': 'Erreur'})}\n\n",
|
50 |
mimetype='text/event-stream'), 400
|
51 |
|
52 |
model_to_use = DEEPTHINK_MODEL_NAME if use_deepthink else STANDARD_MODEL_NAME
|
@@ -101,7 +103,7 @@ def gpt_francais():
|
|
101 |
|
102 |
except Exception:
|
103 |
logging.exception("Erreur pendant la génération de contenu.")
|
104 |
-
yield f"data: {json.dumps({'type': 'error', 'content': 'Erreur'})}\n\n"
|
105 |
|
106 |
return Response(generate_stream(), mimetype='text/event-stream')
|
107 |
|
@@ -111,13 +113,13 @@ def gpt_francais_cc():
|
|
111 |
|
112 |
if 'images' not in request.files:
|
113 |
logging.warning("Aucun fichier image reçu.")
|
114 |
-
return Response(f"data: {json.dumps({'type': 'error', 'content': '
|
115 |
mimetype='text/event-stream'), 400
|
116 |
|
117 |
images = request.files.getlist('images')
|
118 |
-
if not images:
|
119 |
logging.warning("Liste d'images vide.")
|
120 |
-
return Response(f"data: {json.dumps({'type': 'error', 'content': '
|
121 |
mimetype='text/event-stream'), 400
|
122 |
|
123 |
def generate_image_analysis():
|
@@ -158,11 +160,12 @@ def gpt_francais_cc():
|
|
158 |
yield f"data: {json.dumps({'type': 'content', 'content': part.text})}\n\n"
|
159 |
|
160 |
logging.info("Fin du streaming d'analyse d'image.")
|
|
|
161 |
yield f"data: {json.dumps({'type': 'done'})}\n\n"
|
162 |
|
163 |
except Exception:
|
164 |
logging.exception("Erreur pendant l'analyse d'image.")
|
165 |
-
yield f"data: {json.dumps({'type': 'error', 'content': 'Erreur'})}\n\n"
|
166 |
|
167 |
return Response(generate_image_analysis(), mimetype='text/event-stream')
|
168 |
|
|
|
36 |
|
37 |
@app.route('/api/francais', methods=['POST','GET'])
|
38 |
def gpt_francais():
|
39 |
+
# FIX: The frontend uses EventSource which sends a GET request.
|
40 |
+
# Data must be read from `request.args` (query string) instead of `request.form`.
|
41 |
+
logging.info(f"Requête {request.method} reçue sur /api/francais")
|
42 |
+
french_prompt = request.args.get('sujet', '').strip()
|
43 |
+
choix = request.args.get('choix', '').strip()
|
44 |
+
style = request.args.get('style', '').strip()
|
45 |
+
use_deepthink = request.args.get('use_deepthink', 'false').lower() == 'true'
|
46 |
|
47 |
logging.info(f"Données reçues : sujet='{french_prompt[:50]}', choix='{choix}', style='{style}', deepthink={use_deepthink}")
|
48 |
|
49 |
if not french_prompt:
|
50 |
logging.warning("Sujet vide, retour erreur.")
|
51 |
+
return Response(f"data: {json.dumps({'type': 'error', 'content': 'Erreur: Le sujet ne peut pas être vide.'})}\n\n",
|
52 |
mimetype='text/event-stream'), 400
|
53 |
|
54 |
model_to_use = DEEPTHINK_MODEL_NAME if use_deepthink else STANDARD_MODEL_NAME
|
|
|
103 |
|
104 |
except Exception:
|
105 |
logging.exception("Erreur pendant la génération de contenu.")
|
106 |
+
yield f"data: {json.dumps({'type': 'error', 'content': 'Erreur serveur pendant la génération.'})}\n\n"
|
107 |
|
108 |
return Response(generate_stream(), mimetype='text/event-stream')
|
109 |
|
|
|
113 |
|
114 |
if 'images' not in request.files:
|
115 |
logging.warning("Aucun fichier image reçu.")
|
116 |
+
return Response(f"data: {json.dumps({'type': 'error', 'content': 'Aucun fichier image envoyé.'})}\n\n",
|
117 |
mimetype='text/event-stream'), 400
|
118 |
|
119 |
images = request.files.getlist('images')
|
120 |
+
if not images or not images[0].filename:
|
121 |
logging.warning("Liste d'images vide.")
|
122 |
+
return Response(f"data: {json.dumps({'type': 'error', 'content': 'Aucune image sélectionnée.'})}\n\n",
|
123 |
mimetype='text/event-stream'), 400
|
124 |
|
125 |
def generate_image_analysis():
|
|
|
160 |
yield f"data: {json.dumps({'type': 'content', 'content': part.text})}\n\n"
|
161 |
|
162 |
logging.info("Fin du streaming d'analyse d'image.")
|
163 |
+
# Note: The original code was missing a final "done" signal here.
|
164 |
yield f"data: {json.dumps({'type': 'done'})}\n\n"
|
165 |
|
166 |
except Exception:
|
167 |
logging.exception("Erreur pendant l'analyse d'image.")
|
168 |
+
yield f"data: {json.dumps({'type': 'error', 'content': 'Erreur serveur pendant l\\'analyse de l\\'image.'})}\n\n"
|
169 |
|
170 |
return Response(generate_image_analysis(), mimetype='text/event-stream')
|
171 |
|