Docfile commited on
Commit
7755c1f
·
verified ·
1 Parent(s): 4c16fc2

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +139 -0
app.py ADDED
@@ -0,0 +1,139 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from flask import Flask, render_template, request, jsonify
2
+ import google.generativeai as genai
3
+ import os
4
+ from PIL import Image
5
+ import tempfile
6
+
7
+ app = Flask(__name__)
8
+
9
+ # Configuration de l'API Gemini
10
+ token = os.environ.get("TOKEN")
11
+ genai.configure(api_key=token)
12
+
13
+ generation_config = {
14
+ "temperature": 1,
15
+ "max_output_tokens": 8192,
16
+ }
17
+
18
+ safety_settings = [
19
+ {"category": "HARM_CATEGORY_HARASSMENT", "threshold": "BLOCK_NONE"},
20
+ {"category": "HARM_CATEGORY_HATE_SPEECH", "threshold": "BLOCK_NONE"},
21
+ {"category": "HARM_CATEGORY_SEXUALLY_EXPLICIT", "threshold": "BLOCK_NONE"},
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')
35
+
36
+
37
+
38
+ @app.route('/api/francais', methods=['POST'])
39
+ @telegram_notification
40
+ def gpt_francais():
41
+ """Handles French questions."""
42
+ french_prompt = request.form.get('sujet', '').strip()
43
+ choix = request.form.get('choix', '').strip()
44
+ style = request.form.get('style', '').strip()
45
+
46
+ if not french_prompt:
47
+ return jsonify({"output": "Veuillez saisir un thème."}), 400
48
+
49
+ if choix == "discuter":
50
+ prompt = f""" Je veux faire mon travail de français de niveau lycée sous la forme d'un travail argumentatif.
51
+ La question du travail est la suivante : "{french_prompt}". Tu devras discuter ce thème.
52
+ tu utiliseras la méthodologie suivante :
53
+
54
+ # INTRODUCTION:
55
+ - Approche par constat
56
+ - Problématique
57
+ - Annonce du plan
58
+
59
+ # DÉVELOPPEMENT:
60
+ - Introduction partielle (énonce la thèse)
61
+ - Argument 1:
62
+ * Explications
63
+ * Illustration (exemple + explication)
64
+ - Argument 2:
65
+ * Explications
66
+ * Illustration (exemple + explication)
67
+ - Argument 3:
68
+ * Explications
69
+ * Illustration (exemple + explication)
70
+
71
+ # phrase de Transiton vers la deuxieme partie :
72
+
73
+ - Introduction partielle (énonce l'antithèse)
74
+ - Argument 1:
75
+ * Explications
76
+ * Illustration (exemple + explication)
77
+ - Argument 2:
78
+ * Explications
79
+ * Illustration (exemple + explication)
80
+ - Argument 3:
81
+ * Explications
82
+ * Illustration (exemple + explication)
83
+
84
+ #Conclusion
85
+ * Bilan
86
+ * Ouverture du sujet
87
+
88
+ Je veux que tu utilises un style d'écriture {style}."""
89
+
90
+ else:
91
+ prompt = f"""Je veux faire mon travail de français de niveau lycé sous la forme d'un travail argumentatif.
92
+ La question du travail est la suivante : "{french_prompt}". Tu devras {choix} ce thème.
93
+ tu utiliseras la méthodologie suivante :
94
+
95
+ # INTRODUCTION:
96
+ - Approche par constat
97
+ - Problématique
98
+ - Annonce du plan
99
+
100
+ # DÉVELOPPEMENT:
101
+ - Phrase chapeau (énonce la thèse)
102
+ - Argument 1:
103
+ * Explications
104
+ * Illustration (exemple + explication)
105
+ - Argument 2:
106
+ * Explications
107
+ * Illustration (exemple + explication)
108
+ - Argument 3:
109
+ * Explications
110
+ * Illustration (exemple + explication)
111
+
112
+ #Conclusion
113
+ * Bilan (thèse + arguments1 + arguments2+arguments3)
114
+ * Ouverture du sujet
115
+
116
+ Je veux que tu utilises un style d'écriture {style}."""
117
+
118
+ try:
119
+ response = model.generate_content(prompt)
120
+ return jsonify({"output": response.text}), 200
121
+ except Exception as e:
122
+ return jsonify({"output": str(e)}), 500
123
+
124
+ @app.route('/api/etude-texte', methods=['POST'])
125
+ @telegram_notification
126
+ def gpt_francais_cc():
127
+ """Handles text analysis for French (currently under development)."""
128
+ if 'image' not in request.files:
129
+ return jsonify({"output": "Aucune image n'a été téléchargée."}), 400
130
+
131
+ pre_prompt = "Fais un tableau des outils à utiliser pour ce commentaire composé. Je veux les outils, repérage, et interprétation."
132
+
133
+ try:
134
+ response = "Rend toi dans Mariam je réfléchis"
135
+ return jsonify({"output": response}), 200
136
+ except Exception as e:
137
+ return jsonify({"output": str(e)}), 500
138
+
139
+ # Other Routes