Spaces:
Build error
Build error
File size: 1,118 Bytes
d1dce8a |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
import streamlit as st
from google.generativeai import text_model
from PIL import Image
import io
import os
# API-Schlüssel laden
api_key = os.getenv('KEY')
# Gemini API-Modell initialisieren
model = text_model.TextModel.from_pretrained("gemini-2.0-flash")
st.title("Bildanalyse mit Gemini")
uploaded_file = st.file_uploader("Bild hochladen", type=["jpg", "png", "jpeg"])
if uploaded_file is not None:
image = Image.open(uploaded_file)
st.image(image, caption="Hochgeladenes Bild", use_column_width=True)
if st.button("Analysieren"):
# Bild in Bytes umwandeln
image_bytes = io.BytesIO()
image.save(image_bytes, format=image.format)
image_bytes = image_bytes.getvalue()
# Gemini API-Anfrage erstellen
prompt = "Was ist das Hauptobjekt in diesem Bild?"
response = model.generate_text(
model=model,
prompt=prompt,
image=image_bytes,
temperature=0.5,
max_output_tokens=100
)
# Antwort anzeigen
st.write("## Analyseergebnis:")
st.write(response.result) |