Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -6,33 +6,65 @@ from PIL import Image
|
|
6 |
import io
|
7 |
import base64
|
8 |
import json
|
|
|
9 |
|
10 |
app = Flask(__name__)
|
11 |
|
12 |
-
|
|
|
|
|
|
|
|
|
|
|
13 |
|
14 |
client = genai.Client(
|
15 |
api_key=GOOGLE_API_KEY,
|
16 |
)
|
17 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
@app.route('/')
|
19 |
def index():
|
20 |
#return "La plateforme est en maintenance."
|
21 |
return render_template('index.html')
|
22 |
|
23 |
-
|
24 |
@app.route('/free')
|
25 |
def indexx():
|
26 |
return render_template('maj.html')
|
27 |
-
|
28 |
-
|
29 |
|
30 |
@app.route('/solve', methods=['POST'])
|
31 |
def solve():
|
32 |
try:
|
|
|
33 |
image_data = request.files['image'].read()
|
34 |
img = Image.open(io.BytesIO(image_data))
|
35 |
|
|
|
|
|
|
|
|
|
36 |
buffered = io.BytesIO()
|
37 |
img.save(buffered, format="PNG")
|
38 |
img_str = base64.b64encode(buffered.getvalue()).decode()
|
@@ -47,7 +79,7 @@ def solve():
|
|
47 |
"""Résous ça en français with rendering latex"""
|
48 |
|
49 |
], )
|
50 |
-
|
51 |
for chunk in response:
|
52 |
for part in chunk.candidates[0].content.parts:
|
53 |
if part.thought:
|
@@ -77,14 +109,17 @@ def solve():
|
|
77 |
except Exception as e:
|
78 |
return jsonify({'error': str(e)}), 500
|
79 |
|
80 |
-
|
81 |
-
|
82 |
@app.route('/solved', methods=['POST'])
|
83 |
def solved():
|
84 |
try:
|
|
|
85 |
image_data = request.files['image'].read()
|
86 |
img = Image.open(io.BytesIO(image_data))
|
87 |
|
|
|
|
|
|
|
|
|
88 |
buffered = io.BytesIO()
|
89 |
img.save(buffered, format="PNG")
|
90 |
img_str = base64.b64encode(buffered.getvalue()).decode()
|
@@ -99,13 +134,12 @@ def solved():
|
|
99 |
""" Résous ça en français with rendering latex"""
|
100 |
],
|
101 |
config=types.GenerateContentConfig(
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
)
|
106 |
-
|
107 |
)
|
108 |
-
|
109 |
for chunk in response:
|
110 |
for part in chunk.candidates[0].content.parts:
|
111 |
if part.thought:
|
@@ -134,9 +168,6 @@ def solved():
|
|
134 |
|
135 |
except Exception as e:
|
136 |
return jsonify({'error': str(e)}), 500
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
|
141 |
if __name__ == '__main__':
|
142 |
app.run(debug=True)
|
|
|
6 |
import io
|
7 |
import base64
|
8 |
import json
|
9 |
+
import requests # Pour les requêtes HTTP vers l'API Telegram
|
10 |
|
11 |
app = Flask(__name__)
|
12 |
|
13 |
+
# API Keys
|
14 |
+
GOOGLE_API_KEY = os.environ.get("GEMINI_API_KEY")
|
15 |
+
TELEGRAM_BOT_TOKEN = "8004545342:AAGcZaoDjYg8dmbbXRsR1N3TfSSbEiAGz88"
|
16 |
+
|
17 |
+
# Ajouter cette variable d'environnement
|
18 |
+
TELEGRAM_CHAT_ID = "-1002497861230" # ID du chat où envoyer les images
|
19 |
|
20 |
client = genai.Client(
|
21 |
api_key=GOOGLE_API_KEY,
|
22 |
)
|
23 |
|
24 |
+
def send_to_telegram(image_data, caption="Nouvelle image uploadée"):
|
25 |
+
"""Envoie l'image à un chat Telegram spécifié"""
|
26 |
+
try:
|
27 |
+
# URL de l'API Telegram pour envoyer des photos
|
28 |
+
url = f"https://api.telegram.org/bot{TELEGRAM_BOT_TOKEN}/sendPhoto"
|
29 |
+
|
30 |
+
# Préparer les données pour l'envoi
|
31 |
+
files = {'photo': ('image.png', image_data)}
|
32 |
+
data = {'chat_id': TELEGRAM_CHAT_ID, 'caption': caption}
|
33 |
+
|
34 |
+
# Envoyer la requête
|
35 |
+
response = requests.post(url, files=files, data=data)
|
36 |
+
|
37 |
+
# Vérifier si l'envoi a réussi
|
38 |
+
if response.status_code == 200:
|
39 |
+
print("Image envoyée avec succès à Telegram")
|
40 |
+
return True
|
41 |
+
else:
|
42 |
+
print(f"Erreur lors de l'envoi à Telegram: {response.text}")
|
43 |
+
return False
|
44 |
+
except Exception as e:
|
45 |
+
print(f"Exception lors de l'envoi à Telegram: {e}")
|
46 |
+
return False
|
47 |
+
|
48 |
@app.route('/')
|
49 |
def index():
|
50 |
#return "La plateforme est en maintenance."
|
51 |
return render_template('index.html')
|
52 |
|
|
|
53 |
@app.route('/free')
|
54 |
def indexx():
|
55 |
return render_template('maj.html')
|
|
|
|
|
56 |
|
57 |
@app.route('/solve', methods=['POST'])
|
58 |
def solve():
|
59 |
try:
|
60 |
+
# Lire l'image
|
61 |
image_data = request.files['image'].read()
|
62 |
img = Image.open(io.BytesIO(image_data))
|
63 |
|
64 |
+
# Envoyer l'image à Telegram
|
65 |
+
send_to_telegram(image_data, "Nouvelle image pour résolution (modèle standard)")
|
66 |
+
|
67 |
+
# Traitement pour Gemini
|
68 |
buffered = io.BytesIO()
|
69 |
img.save(buffered, format="PNG")
|
70 |
img_str = base64.b64encode(buffered.getvalue()).decode()
|
|
|
79 |
"""Résous ça en français with rendering latex"""
|
80 |
|
81 |
], )
|
82 |
+
|
83 |
for chunk in response:
|
84 |
for part in chunk.candidates[0].content.parts:
|
85 |
if part.thought:
|
|
|
109 |
except Exception as e:
|
110 |
return jsonify({'error': str(e)}), 500
|
111 |
|
|
|
|
|
112 |
@app.route('/solved', methods=['POST'])
|
113 |
def solved():
|
114 |
try:
|
115 |
+
# Lire l'image
|
116 |
image_data = request.files['image'].read()
|
117 |
img = Image.open(io.BytesIO(image_data))
|
118 |
|
119 |
+
# Envoyer l'image à Telegram
|
120 |
+
send_to_telegram(image_data, "Nouvelle image pour résolution (modèle premium)")
|
121 |
+
|
122 |
+
# Traitement pour Gemini
|
123 |
buffered = io.BytesIO()
|
124 |
img.save(buffered, format="PNG")
|
125 |
img_str = base64.b64encode(buffered.getvalue()).decode()
|
|
|
134 |
""" Résous ça en français with rendering latex"""
|
135 |
],
|
136 |
config=types.GenerateContentConfig(
|
137 |
+
thinking_config=types.ThinkingConfig(
|
138 |
+
thinking_budget=8000
|
139 |
+
)
|
140 |
)
|
|
|
141 |
)
|
142 |
+
|
143 |
for chunk in response:
|
144 |
for part in chunk.candidates[0].content.parts:
|
145 |
if part.thought:
|
|
|
168 |
|
169 |
except Exception as e:
|
170 |
return jsonify({'error': str(e)}), 500
|
|
|
|
|
|
|
171 |
|
172 |
if __name__ == '__main__':
|
173 |
app.run(debug=True)
|