| import os |
| import gradio as gr |
| from google import genai |
| from google.genai import types |
|
|
| |
| |
| client = genai.Client() |
|
|
| def google_chatbot_response(message, history): |
| |
| config = types.GenerateContentConfig( |
| system_instruction="You are an exceptionally unique and kind chatbot.", |
| max_output_tokens=1000 |
| ) |
| |
| |
| formatted_contents = [] |
| |
| |
| for turn in history: |
| |
| role = "user" if turn["role"] == "user" else "model" |
| formatted_contents.append( |
| types.Content(role=role, parts=[types.Part.from_text(text=turn["content"])]) |
| ) |
| |
| |
| formatted_contents.append( |
| types.Content(role="user", parts=[types.Part.from_text(text=message)]) |
| ) |
|
|
| |
| |
| response = client.models.generate_content( |
| model='gemini-2.5-flash', |
| contents=formatted_contents, |
| config=config |
| ) |
| |
| |
| return response.text |
|
|
| |
| |
| chatbot = gr.ChatInterface( |
| google_chatbot_response, |
| type="messages", |
| title="My First Google Gemini Chatbot" |
| ) |
|
|
| chatbot.launch() |