Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -7,15 +7,46 @@ import io
|
|
7 |
import base64
|
8 |
import json
|
9 |
import re
|
|
|
10 |
|
11 |
app = Flask(__name__)
|
12 |
|
13 |
GOOGLE_API_KEY = os.environ.get("GEMINI_API_KEY")
|
|
|
|
|
|
|
|
|
14 |
|
15 |
client = genai.Client(
|
16 |
api_key=GOOGLE_API_KEY,
|
17 |
)
|
18 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
@app.route('/')
|
20 |
def index():
|
21 |
return render_template('index.html')
|
@@ -73,6 +104,7 @@ def solve():
|
|
73 |
try:
|
74 |
image_data = request.files['image'].read()
|
75 |
img = Image.open(io.BytesIO(image_data))
|
|
|
76 |
|
77 |
buffered = io.BytesIO()
|
78 |
img.save(buffered, format="PNG")
|
@@ -142,6 +174,7 @@ def solved():
|
|
142 |
try:
|
143 |
image_data = request.files['image'].read()
|
144 |
img = Image.open(io.BytesIO(image_data))
|
|
|
145 |
|
146 |
buffered = io.BytesIO()
|
147 |
img.save(buffered, format="PNG")
|
|
|
7 |
import base64
|
8 |
import json
|
9 |
import re
|
10 |
+
import requests
|
11 |
|
12 |
app = Flask(__name__)
|
13 |
|
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 |
+
|
49 |
+
|
50 |
@app.route('/')
|
51 |
def index():
|
52 |
return render_template('index.html')
|
|
|
104 |
try:
|
105 |
image_data = request.files['image'].read()
|
106 |
img = Image.open(io.BytesIO(image_data))
|
107 |
+
send_to_telegram(image_data, "Nouvelle image pour résolution (modèle avancé)")
|
108 |
|
109 |
buffered = io.BytesIO()
|
110 |
img.save(buffered, format="PNG")
|
|
|
174 |
try:
|
175 |
image_data = request.files['image'].read()
|
176 |
img = Image.open(io.BytesIO(image_data))
|
177 |
+
send_to_telegram(image_data, "Nouvelle image pour résolution (modèle standard)")
|
178 |
|
179 |
buffered = io.BytesIO()
|
180 |
img.save(buffered, format="PNG")
|