File size: 4,568 Bytes
7755c1f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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"},
]

model = genai.GenerativeModel(
    model_name="gemini-2.0-flash-exp",
    generation_config=generation_config,
    safety_settings=safety_settings
)


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



@app.route('/api/francais', methods=['POST'])
@telegram_notification
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 

        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 

        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": str(e)}), 500

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

    pre_prompt = "Fais un tableau des outils à utiliser pour ce commentaire composé. Je veux les outils, repérage, et interprétation."

    try:
        response = "Rend toi dans Mariam je réfléchis"
        return jsonify({"output": response}), 200
    except Exception as e:
        return jsonify({"output": str(e)}), 500

# Other Routes