|
import os |
|
import gradio as gr |
|
from google import genai |
|
|
|
|
|
client = genai.Client(api_key=os.getenv("GOOGLE_API_KEY")) |
|
|
|
|
|
def get_gemini_response(input, image): |
|
|
|
if input != "": |
|
response = client.models.generate_content( |
|
model="gemini-2.0-flash", |
|
contents=[image, input] |
|
) |
|
|
|
else: |
|
response = client.models.generate_content( |
|
model="gemini-2.0-flash", |
|
contents=[image, '說說這是什麼!'] |
|
) |
|
|
|
return response.text |
|
|
|
|
|
iface = gr.Interface( |
|
|
|
fn=get_gemini_response, |
|
|
|
|
|
|
|
inputs=[ |
|
gr.Textbox(label="Enter your question here:"), |
|
gr.Image(label="Choose an image...", type="pil"), |
|
], |
|
|
|
|
|
outputs=gr.Textbox(label="The response is"), |
|
|
|
title="Gemini Multimodal Bot", |
|
description="Ask Gemini questions about images! 上傳圖片並提出問題!", |
|
) |
|
|
|
iface.launch() |