Update app.py
Browse files
app.py
CHANGED
@@ -34,9 +34,10 @@ def ensure_latex_packages():
|
|
34 |
def generate_latex_response(image, question):
|
35 |
"""Génère une réponse en format LaTeX depuis le modèle Gemini."""
|
36 |
try:
|
|
|
37 |
response = client.models.generate_content(
|
38 |
model="gemini-2.0-flash-thinking-exp",
|
39 |
-
contents=[
|
40 |
)
|
41 |
# Extrait les pensées et la réponse
|
42 |
thoughts = response.candidates[0].content.parts[0].text
|
@@ -94,8 +95,11 @@ def main():
|
|
94 |
uploaded_file = st.file_uploader("Choisissez une image...", type=["png", "jpg", "jpeg"])
|
95 |
|
96 |
if uploaded_file is not None:
|
|
|
|
|
|
|
97 |
# Affiche l'image téléchargée
|
98 |
-
image = Image.open(
|
99 |
st.image(image, caption="Image téléchargée", use_container_width=True)
|
100 |
|
101 |
# Obtient la question de l'utilisateur
|
@@ -105,12 +109,9 @@ def main():
|
|
105 |
if question:
|
106 |
with st.spinner("Génération de la réponse en cours..."):
|
107 |
# Convertit l'image PIL en bytes pour l'API Gemini
|
108 |
-
|
109 |
-
image.save(bytes_data, format='PNG')
|
110 |
-
image_bytes = bytes_data.getvalue()
|
111 |
-
|
112 |
# Génère la réponse LaTeX
|
113 |
-
latex_response = generate_latex_response(
|
114 |
|
115 |
# Affiche la réponse LaTeX
|
116 |
st.markdown("### Code LaTeX généré:")
|
|
|
34 |
def generate_latex_response(image, question):
|
35 |
"""Génère une réponse en format LaTeX depuis le modèle Gemini."""
|
36 |
try:
|
37 |
+
images = Image.open(image)
|
38 |
response = client.models.generate_content(
|
39 |
model="gemini-2.0-flash-thinking-exp",
|
40 |
+
contents=[images, question],
|
41 |
)
|
42 |
# Extrait les pensées et la réponse
|
43 |
thoughts = response.candidates[0].content.parts[0].text
|
|
|
95 |
uploaded_file = st.file_uploader("Choisissez une image...", type=["png", "jpg", "jpeg"])
|
96 |
|
97 |
if uploaded_file is not None:
|
98 |
+
with tempfile.NamedTemporaryFile(delete=False, suffix='.png') as tmp_file:
|
99 |
+
tmp_file.write(uploaded_file.getvalue())
|
100 |
+
temp_image_path = tmp_file.name
|
101 |
# Affiche l'image téléchargée
|
102 |
+
image = Image.open(temp_image_path)
|
103 |
st.image(image, caption="Image téléchargée", use_container_width=True)
|
104 |
|
105 |
# Obtient la question de l'utilisateur
|
|
|
109 |
if question:
|
110 |
with st.spinner("Génération de la réponse en cours..."):
|
111 |
# Convertit l'image PIL en bytes pour l'API Gemini
|
112 |
+
|
|
|
|
|
|
|
113 |
# Génère la réponse LaTeX
|
114 |
+
latex_response = generate_latex_response(temp_image_path, question)
|
115 |
|
116 |
# Affiche la réponse LaTeX
|
117 |
st.markdown("### Code LaTeX généré:")
|