Docfile commited on
Commit
de76b86
·
verified ·
1 Parent(s): a1e5914

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -17
app.py CHANGED
@@ -243,12 +243,14 @@ model = genai.GenerativeModel(
243
  safety_settings=safety_settings
244
  )
245
 
246
- def generate_table(image):
247
- """Génère le tableau d'analyse à partir de l'image"""
248
- response = model.generate_content([prompt_tableau, image])
249
-
 
250
  return response.text
251
 
 
252
  def generate_dissertation(tableau):
253
  """Génère la dissertation basée sur le tableau"""
254
  prompt = f"""
@@ -297,27 +299,20 @@ def analyzed():
297
  os.unlink(temp_file.name)
298
 
299
 
300
-
301
-
302
  @app.route('/analyze', methods=['POST'])
303
  def analyze():
304
  if 'image' not in request.files:
305
  return jsonify({'error': 'No image uploaded'}), 400
306
-
307
-
 
308
  image_file = request.files['image']
309
-
310
- # Sauvegarder temporairement l'image
311
  with tempfile.NamedTemporaryFile(delete=False) as temp_file:
312
  image_file.save(temp_file.name)
313
  image = Image.open(temp_file.name)
314
 
315
-
316
  try:
317
- # Première génération : le tableau
318
- tableau = generate_table(image)
319
-
320
- # Deuxième génération : la dissertation
321
  dissertation = generate_dissertation(tableau)
322
 
323
  return jsonify({
@@ -327,5 +322,4 @@ def analyze():
327
  except Exception as e:
328
  return jsonify({'error': "Erreur."}), 500
329
  finally:
330
- # Nettoyer le fichier temporaire
331
- os.unlink(temp_file.name)
 
243
  safety_settings=safety_settings
244
  )
245
 
246
+ def generate_table(image, consignes=""):
247
+ prompt = prompt_tableau
248
+ if consignes:
249
+ prompt += "\n" + consignes
250
+ response = model.generate_content([prompt, image])
251
  return response.text
252
 
253
+
254
  def generate_dissertation(tableau):
255
  """Génère la dissertation basée sur le tableau"""
256
  prompt = f"""
 
299
  os.unlink(temp_file.name)
300
 
301
 
 
 
302
  @app.route('/analyze', methods=['POST'])
303
  def analyze():
304
  if 'image' not in request.files:
305
  return jsonify({'error': 'No image uploaded'}), 400
306
+
307
+ consignes = request.form.get("consignes", "")
308
+
309
  image_file = request.files['image']
 
 
310
  with tempfile.NamedTemporaryFile(delete=False) as temp_file:
311
  image_file.save(temp_file.name)
312
  image = Image.open(temp_file.name)
313
 
 
314
  try:
315
+ tableau = generate_table(image, consignes)
 
 
 
316
  dissertation = generate_dissertation(tableau)
317
 
318
  return jsonify({
 
322
  except Exception as e:
323
  return jsonify({'error': "Erreur."}), 500
324
  finally:
325
+ os.unlink(temp_file.name)