File size: 5,054 Bytes
7755c1f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0b9d6a6
7755c1f
0b9d6a6
7755c1f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1e9998c
7755c1f
1e9998c
7755c1f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ba1ef6a
7755c1f
 
 
 
 
 
 
6404f2c
7755c1f
 
 
0b9d6a6
 
7755c1f
 
0b9d6a6
 
 
 
82b4eb0
0b9d6a6
 
 
 
 
 
 
 
7755c1f
 
0b9d6a6
 
7755c1f
 
 
0b9d6a6
 
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
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 de l'API Gemini
token = os.environ.get("TOKEN")
genai.configure(api_key=token)

generation_config = {
    "temperature": 1,
    "max_output_tokens": 8192,
}

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"},
]

# Choose the Gemini model (make sure it supports multiple images)
model = genai.GenerativeModel(
    model_name="gemini-2.0-flash-exp", # Or gemini-1.5-pro if available
    generation_config=generation_config,
    safety_settings=safety_settings
)

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



@app.route('/api/francais', methods=['POST'])
def gpt_francais():
    """Handles French questions."""
    french_prompt = request.form.get('sujet', '').strip()
    choix = request.form.get('choix', '').strip()
    style = request.form.get('style', '').strip()

    if not french_prompt:
        return jsonify({"output": "Veuillez saisir un thème."}), 400

    if choix == "discuter":
        prompt = f""" Je veux faire mon travail de français de niveau lycée sous la forme d'un travail argumentatif. 
        La question du travail est la suivante : "{french_prompt}". Tu devras discuter ce thème. 
        tu utiliseras la méthodologie suivante :

        # INTRODUCTION:
            - Approche par constat
            - Problématique 
            - Annonce du plan 

            # DÉVELOPPEMENT:
            - Introduction partielle (énonce la thèse)
            - Argument 1:
                * Explications
                * Illustration (exemple + explication)
            - Argument 2:
                * Explications
                * Illustration (exemple + explication)
           - Argument 3:
                * Explications
                * Illustration (exemple + explication)

            # phrase de Transiton vers la deuxieme partie :

            - Introduction partielle (énonce l'antithèse)
            - Argument 1:
                * Explications
                * Illustration (exemple + explication)
            - Argument 2:
                * Explications
                * Illustration (exemple + explication)
           - Argument 3:
                * Explications
                * Illustration (exemple + explication)

            #Conclusion 
                * Bilan 
                * Ouverture du sujet (sous forme de phrase interrogative )

        Je veux que tu utilises un style d'écriture {style}."""

    else:
        prompt = f"""Je veux faire mon travail de français de niveau lycé sous la forme d'un travail argumentatif. 
        La question du travail est la suivante : "{french_prompt}". Tu devras {choix} ce thème. 
        tu utiliseras la méthodologie suivante :

        # INTRODUCTION:
            - Approche par constat
            - Problématique 
            - Annonce du plan 

            # DÉVELOPPEMENT:
            - Phrase chapeau (énonce la thèse)
            - Argument 1:
                * Explications
                * Illustration (exemple + explication)
            - Argument 2:
                * Explications
                * Illustration (exemple + explication)
           - Argument 3:
                * Explications
                * Illustration (exemple + explication)

            #Conclusion 
                * Bilan (thèse + arguments1 + arguments2+arguments3)
                * Ouverture du sujet ( sous forme de phrase interrogative )

        Je veux que tu utilises un style d'écriture {style}."""

    try:
        response = model.generate_content(prompt)
        return jsonify({"output": response.text}), 200
    except Exception as e:
        return jsonify({"output": "eror"}), 500

@app.route('/api/etude-texte', methods=['POST'])
def gpt_francais_cc():
    """Handles text analysis for French with multiple images."""
    if 'images' not in request.files:
        return jsonify({"output": "Aucune image n'a été téléchargée."}), 400

    images = request.files.getlist('images')
    if not images:
        return jsonify({"output": "Aucune image selectionnée."}), 400

    pre_prompt = "Traite entièrement ce sujet de français."
    image_parts = []

    for image in images:
        try:
            img = Image.open(image)
            image_parts.append(img)
        except Exception as e:
            return jsonify({"output": f"Erreur lors du traitement de l'image : {e}"}), 500

    try:
        response = model.generate_content([pre_prompt] + image_parts)
        return jsonify({"output": response.text}), 200
    except Exception as e:
        return jsonify({"output": str(e)}), 500

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