Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -22,13 +22,13 @@ safety_settings = [
|
|
22 |
{"category": "HARM_CATEGORY_DANGEROUS_CONTENT", "threshold": "BLOCK_NONE"},
|
23 |
]
|
24 |
|
|
|
25 |
model = genai.GenerativeModel(
|
26 |
-
model_name="gemini-2.0-flash-exp",
|
27 |
generation_config=generation_config,
|
28 |
safety_settings=safety_settings
|
29 |
)
|
30 |
|
31 |
-
|
32 |
@app.route('/')
|
33 |
def index():
|
34 |
return render_template('index.html')
|
@@ -122,16 +122,29 @@ def gpt_francais():
|
|
122 |
|
123 |
@app.route('/api/etude-texte', methods=['POST'])
|
124 |
def gpt_francais_cc():
|
125 |
-
"""Handles text analysis for French
|
126 |
-
if '
|
127 |
return jsonify({"output": "Aucune image n'a été téléchargée."}), 400
|
128 |
|
|
|
|
|
|
|
|
|
129 |
pre_prompt = "Fais un tableau des outils à utiliser pour ce commentaire composé. Je veux les outils, repérage, et interprétation."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
130 |
|
131 |
try:
|
132 |
-
response =
|
133 |
-
return jsonify({"output": response}), 200
|
134 |
except Exception as e:
|
135 |
return jsonify({"output": str(e)}), 500
|
136 |
|
137 |
-
|
|
|
|
22 |
{"category": "HARM_CATEGORY_DANGEROUS_CONTENT", "threshold": "BLOCK_NONE"},
|
23 |
]
|
24 |
|
25 |
+
# Choose the Gemini model (make sure it supports multiple images)
|
26 |
model = genai.GenerativeModel(
|
27 |
+
model_name="gemini-2.0-flash-exp", # Or gemini-1.5-pro if available
|
28 |
generation_config=generation_config,
|
29 |
safety_settings=safety_settings
|
30 |
)
|
31 |
|
|
|
32 |
@app.route('/')
|
33 |
def index():
|
34 |
return render_template('index.html')
|
|
|
122 |
|
123 |
@app.route('/api/etude-texte', methods=['POST'])
|
124 |
def gpt_francais_cc():
|
125 |
+
"""Handles text analysis for French with multiple images."""
|
126 |
+
if 'images' not in request.files:
|
127 |
return jsonify({"output": "Aucune image n'a été téléchargée."}), 400
|
128 |
|
129 |
+
images = request.files.getlist('images')
|
130 |
+
if not images:
|
131 |
+
return jsonify({"output": "Aucune image selectionnée."}), 400
|
132 |
+
|
133 |
pre_prompt = "Fais un tableau des outils à utiliser pour ce commentaire composé. Je veux les outils, repérage, et interprétation."
|
134 |
+
image_parts = []
|
135 |
+
|
136 |
+
for image in images:
|
137 |
+
try:
|
138 |
+
img = Image.open(image)
|
139 |
+
image_parts.append(img)
|
140 |
+
except Exception as e:
|
141 |
+
return jsonify({"output": f"Erreur lors du traitement de l'image : {e}"}), 500
|
142 |
|
143 |
try:
|
144 |
+
response = model.generate_content([pre_prompt] + image_parts)
|
145 |
+
return jsonify({"output": response.text}), 200
|
146 |
except Exception as e:
|
147 |
return jsonify({"output": str(e)}), 500
|
148 |
|
149 |
+
if __name__ == '__main__':
|
150 |
+
app.run(debug=True)
|