Simple implementation of Gemini Pro with Gradio chat interface, including real-time search capability.
Code
import gradio as gr
import google.generativeai as genai
GEMINI_API_KEY = "YOUR_API_KEY"
genai.configure(api_key=GEMINI_API_KEY)
model = genai.GenerativeModel('models/gemini-1.5-pro-002')
def process_query(message, history):
try:
response = model.generate_content(
contents=message,
tools='google_search_retrieval'
)
return response.text
except Exception as e:
return f"Error occurred: {str(e)}"
interface = gr.ChatInterface(
fn=process_query,
title='Gemini-Gradio Integration with Search',
description="Chat with Gemini Pro model (includes real-time search capability).",
examples=[
"Explain quantum gravity to a 5-year old.",
"How many R are there in the word Strawberry?",
"Who won Wimbledon this year?"
],
theme=gr.themes.Soft()
)
if __name__ == "__main__":
interface.launch(share=True)
Setup
Install required packages:
pip install gradio google-generativeai
Replace YOUR_API_KEY with your actual Gemini API key
Gemini Pro Chat Interface with Gradio
Simple implementation of Gemini Pro with Gradio chat interface, including real-time search capability.
Code
Setup
Install required packages:
Replace
YOUR_API_KEY
with your actual Gemini API keyRun the script:
Hope this will help for others :)