Spaces:
Build error
Build error
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) |