Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -20,34 +20,28 @@ st.title("Bildanalyse mit Gemini")
|
|
20 |
uploaded_file = st.file_uploader("Bild hochladen", type=["jpg", "png", "jpeg"])
|
21 |
|
22 |
if uploaded_file is not None:
|
23 |
-
|
24 |
-
st.image(image, caption="Hochgeladenes Bild", use_column_width=True)
|
25 |
|
26 |
if st.button("Analysieren"):
|
27 |
-
with st.spinner("Analysiere Bild..."):
|
28 |
try:
|
29 |
-
# Bild in Bytes umwandeln
|
30 |
image_bytes = io.BytesIO()
|
31 |
image.save(image_bytes, format=image.format)
|
32 |
image_bytes = image_bytes.getvalue()
|
33 |
|
34 |
-
#
|
35 |
-
|
36 |
-
content=image_bytes, mime_type=f"image/{image.format.lower()}" # MIME-Type dynamisch
|
37 |
-
)
|
38 |
|
39 |
-
# Prompt erstellen (angepasst)
|
40 |
-
prompt = "Beschreibe dieses Bild und identifiziere das Hauptobjekt
|
41 |
|
42 |
-
# Anfrage an Gemini senden
|
43 |
-
response = model.generate_text(
|
44 |
-
prompt=prompt,
|
45 |
-
image=file_like_object, # Bild direkt übergeben
|
46 |
-
)
|
47 |
|
48 |
# Antwort anzeigen
|
49 |
st.write("## Analyseergebnis:")
|
50 |
st.write(response.result)
|
51 |
|
52 |
except Exception as e:
|
53 |
-
st.error(f"Ein Fehler ist aufgetreten: {e}")
|
|
|
20 |
uploaded_file = st.file_uploader("Bild hochladen", type=["jpg", "png", "jpeg"])
|
21 |
|
22 |
if uploaded_file is not None:
|
23 |
+
# ... (Bild anzeigen wie zuvor)
|
|
|
24 |
|
25 |
if st.button("Analysieren"):
|
26 |
+
with st.spinner("Analysiere Bild..."):
|
27 |
try:
|
28 |
+
# Bild in Bytes umwandeln
|
29 |
image_bytes = io.BytesIO()
|
30 |
image.save(image_bytes, format=image.format)
|
31 |
image_bytes = image_bytes.getvalue()
|
32 |
|
33 |
+
# Bild in Base64 kodieren
|
34 |
+
encoded_image = base64.b64encode(image_bytes).decode("utf-8")
|
|
|
|
|
35 |
|
36 |
+
# Prompt erstellen (angepasst für Base64)
|
37 |
+
prompt = f"Beschreibe dieses Bild (Base64-kodiert) und identifiziere das Hauptobjekt:\n\n{encoded_image}"
|
38 |
|
39 |
+
# Anfrage an Gemini senden
|
40 |
+
response = model.generate_text(prompt=prompt)
|
|
|
|
|
|
|
41 |
|
42 |
# Antwort anzeigen
|
43 |
st.write("## Analyseergebnis:")
|
44 |
st.write(response.result)
|
45 |
|
46 |
except Exception as e:
|
47 |
+
st.error(f"Ein Fehler ist aufgetreten: {e}")
|