Spaces:
Sleeping
Sleeping
Commit
·
5a958cd
1
Parent(s):
236cd54
app.py
CHANGED
|
@@ -9,14 +9,6 @@ genai.configure(api_key=API_KEY)
|
|
| 9 |
# Use Gemini 1.5 Flash (free-tier accessible)
|
| 10 |
model = genai.GenerativeModel("gemini-1.5-flash")
|
| 11 |
|
| 12 |
-
def chatbot(prompt, history=[]):
|
| 13 |
-
"""Generates a chatbot response using the free-tier Gemini API."""
|
| 14 |
-
try:
|
| 15 |
-
response = model.generate_content(prompt)
|
| 16 |
-
return response.text
|
| 17 |
-
except Exception as e:
|
| 18 |
-
return f"Error: {e}"
|
| 19 |
-
|
| 20 |
def vqa(image, question):
|
| 21 |
"""Performs Visual Question Answering (VQA) using the Gemini API."""
|
| 22 |
try:
|
|
@@ -26,11 +18,6 @@ def vqa(image, question):
|
|
| 26 |
return f"Error: {e}"
|
| 27 |
|
| 28 |
# Create Gradio interfaces
|
| 29 |
-
chat_interface = gr.ChatInterface(
|
| 30 |
-
chatbot,
|
| 31 |
-
title="Free Gemini API Chatbot",
|
| 32 |
-
description="Ae chatbot powered by the free-tier Google Gemini API."
|
| 33 |
-
)
|
| 34 |
|
| 35 |
vqa_interface = gr.Interface(
|
| 36 |
fn=vqa,
|
|
@@ -40,9 +27,6 @@ vqa_interface = gr.Interface(
|
|
| 40 |
description="Upload an image and ask a question about it."
|
| 41 |
)
|
| 42 |
|
| 43 |
-
# Combine interfaces
|
| 44 |
-
with gr.Blocks() as demo:
|
| 45 |
-
gr.TabbedInterface([chat_interface, vqa_interface], ["Chatbot", "VQA"])
|
| 46 |
|
| 47 |
if __name__ == "__main__":
|
| 48 |
demo.launch()
|
|
|
|
| 9 |
# Use Gemini 1.5 Flash (free-tier accessible)
|
| 10 |
model = genai.GenerativeModel("gemini-1.5-flash")
|
| 11 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
def vqa(image, question):
|
| 13 |
"""Performs Visual Question Answering (VQA) using the Gemini API."""
|
| 14 |
try:
|
|
|
|
| 18 |
return f"Error: {e}"
|
| 19 |
|
| 20 |
# Create Gradio interfaces
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
vqa_interface = gr.Interface(
|
| 23 |
fn=vqa,
|
|
|
|
| 27 |
description="Upload an image and ask a question about it."
|
| 28 |
)
|
| 29 |
|
|
|
|
|
|
|
|
|
|
| 30 |
|
| 31 |
if __name__ == "__main__":
|
| 32 |
demo.launch()
|