File size: 1,931 Bytes
24ccb55
a255150
a10ea6b
04084ef
f012284
5f9325a
04084ef
 
 
c60bb61
a255150
04084ef
24ccb55
b30ad3b
 
 
 
 
 
04084ef
a255150
04084ef
89cf4e1
a255150
 
 
 
5f9325a
04084ef
 
ed72a3e
04084ef
4c4251c
04084ef
f012284
 
24ccb55
f012284
24ccb55
4c4251c
24ccb55
4c4251c
 
 
24ccb55
 
a255150
 
19e983b
24ccb55
4c4251c
24ccb55
4c4251c
24ccb55
4c4251c
6822891
b30ad3b
a10ea6b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
from flask import Flask, render_template, request, jsonify
import google.generativeai as genai
import os
from PIL import Image
import tempfile

app = Flask(__name__)

# Configuration Gemini
token = os.environ.get("TOKEN")
genai.configure(api_key=token)


safety_settings = [
    {"category": "HARM_CATEGORY_HARASSMENT", "threshold": "BLOCK_NONE"},
    {"category": "HARM_CATEGORY_HATE_SPEECH", "threshold": "BLOCK_NONE"},
    {"category": "HARM_CATEGORY_SEXUALLY_EXPLICIT", "threshold": "BLOCK_NONE"},
    {"category": "HARM_CATEGORY_DANGEROUS_CONTENT", "threshold": "BLOCK_NONE"},
]

mm = """ resous cet exercice. tu répondras en détaillant au maximum ton procédé de calcul.En français stp et sachant qu'il s'agit d'un devoir niveau terminal s je veux donc une présentation type de cela.  Réponds donc en me donnant directement le devoir et rien d'autre. write you answer in french with rendering Latex"""


model = genai.GenerativeModel(
    model_name="gemini-exp-1206",
    safety_settings=safety_settings
)

@app.route('/')
def home():
    return render_template('index.html')

@app.route('/generate', methods=['POST'])
def generate():
    if 'image' not in request.files:
        return jsonify({'error': 'No image uploaded'}), 400
    
    image_file = request.files['image']
    
    # Sauvegarder temporairement l'image
    with tempfile.NamedTemporaryFile(delete=False) as temp_file:
        image_file.save(temp_file.name)
        try:
            image = Image.open(temp_file.name)
        
            # Générer le contenu
            response = model.generate_content([mm, image])
            result = response.text
              
            return jsonify({"result": result})
        except Exception as e:
             return jsonify({'error': str(e)}), 500
        finally:
        # Nettoyer le fichier temporaire
            os.unlink(temp_file.name)

if __name__ == '__main__':
    app.run(debug=True)