Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -16,33 +16,33 @@ col1, col2 = st.columns(2)
|
|
| 16 |
|
| 17 |
with col1:
|
| 18 |
|
| 19 |
-
uploaded_file = st.file_uploader("Bild hochladen", type=["jpg", "png", "jpeg"])
|
| 20 |
-
|
| 21 |
-
if uploaded_file is not None:
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
with col2:
|
| 47 |
if uploaded_file is not None and response not None:
|
| 48 |
# Antwort anzeigen
|
|
|
|
| 16 |
|
| 17 |
with col1:
|
| 18 |
|
| 19 |
+
uploaded_file = st.file_uploader("Bild hochladen", type=["jpg", "png", "jpeg"])
|
| 20 |
+
|
| 21 |
+
if uploaded_file is not None:
|
| 22 |
+
image = Image.open(uploaded_file)
|
| 23 |
+
st.image(image, caption="Hochgeladenes Bild", use_container_width=True)
|
| 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 |
+
|
| 34 |
+
# Anfrage an Gemini senden
|
| 35 |
+
client = genai.Client(api_key=os.getenv("KEY")) # Client innerhalb der Funktion erstellen
|
| 36 |
+
response = client.models.generate_content(
|
| 37 |
+
model="gemini-2.0-flash-exp", # Oder "gemini-2.0-flash-exp", je nach Verfügbarkeit
|
| 38 |
+
contents=["Beschreibe dieses Bild und identifiziere das Hauptobjekt.", types.Part.from_bytes(data=image_bytes, mime_type=f"image/{image.format.lower()}")
|
| 39 |
+
]
|
| 40 |
+
)
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
except Exception as e:
|
| 45 |
+
st.error(f"Ein Fehler ist aufgetreten: {e}")
|
| 46 |
with col2:
|
| 47 |
if uploaded_file is not None and response not None:
|
| 48 |
# Antwort anzeigen
|