Sebbe33 commited on
Commit
1d8d466
·
verified ·
1 Parent(s): 062f2cb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -6
app.py CHANGED
@@ -4,6 +4,7 @@ from PIL import Image
4
  import io
5
 
6
  from google import genai
 
7
 
8
 
9
  # API-Schlüssel laden
@@ -16,7 +17,7 @@ uploaded_file = st.file_uploader("Bild hochladen", type=["jpg", "png", "jpeg"])
16
 
17
  if uploaded_file is not None:
18
  image = Image.open(uploaded_file)
19
- st.image(image, caption="Hochgeladenes Bild", use_column_width=True)
20
 
21
  if st.button("Analysieren"):
22
  with st.spinner("Analysiere Bild..."):
@@ -26,16 +27,13 @@ if uploaded_file is not None:
26
  image.save(image_bytes, format=image.format)
27
  image_bytes = image_bytes.getvalue()
28
 
29
- # Dateiähnliches Objekt für Gemini erstellen
30
- file_like_object = genai.File(
31
- content=image_bytes, mime_type=f"image/{image.format.lower()}"
32
- )
33
 
34
  # Anfrage an Gemini senden
35
  client = genai.Client(api_key=os.get("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.", file_like_object]
 
39
  )
40
 
41
  # Antwort anzeigen
 
4
  import io
5
 
6
  from google import genai
7
+ from google.genai import types
8
 
9
 
10
  # API-Schlüssel laden
 
17
 
18
  if uploaded_file is not None:
19
  image = Image.open(uploaded_file)
20
+ st.image(image, caption="Hochgeladenes Bild", use_container_width=True)
21
 
22
  if st.button("Analysieren"):
23
  with st.spinner("Analysiere Bild..."):
 
27
  image.save(image_bytes, format=image.format)
28
  image_bytes = image_bytes.getvalue()
29
 
 
 
 
 
30
 
31
  # Anfrage an Gemini senden
32
  client = genai.Client(api_key=os.get("KEY")) # Client innerhalb der Funktion erstellen
33
  response = client.models.generate_content(
34
  model="gemini-2.0-flash-exp", # Oder "gemini-2.0-flash-exp", je nach Verfügbarkeit
35
+ contents=["Beschreibe dieses Bild und identifiziere das Hauptobjekt.", types.Part.from_bytes(data=image_bytes, mime_type=f"image/{image.format.lower()})
36
+ ]
37
  )
38
 
39
  # Antwort anzeigen