Spaces:
Sleeping
Sleeping
import os | |
import gradio as gr | |
import google.generativeai as genai | |
from dotenv import load_dotenv | |
load_dotenv() | |
GEMINI_API_KEY = os.getenv("GEMINI_API_KEY") | |
genai.configure(api_key=GEMINI_API_KEY) | |
def chatbot_response(user_input, mood): | |
mood_prompts = { | |
"Fun": "Respond in a light-hearted, playful manner.", | |
"Serious": "Respond in a thoughtful, serious tone.", | |
"Professional": "Respond in a formal, professional manner.", | |
"Upset": "Respond in a slightly irritated, upset tone." | |
} | |
try: | |
mood_instruction = mood_prompts.get(mood, "") | |
prompt = f"{mood_instruction}\n\nUser: {user_input}\nAI:" | |
response = genai.generate_text(prompt=prompt) | |
reply = response.candidates[0]['text'] | |
return reply | |
except Exception as e: | |
return f"An error occurred: {str(e)}" | |
# Define the Gradio interface | |
iface = gr.Interface( | |
fn=chatbot_response, | |
inputs=[ | |
gr.inputs.Textbox(lines=2, placeholder="Enter your message here..."), | |
gr.inputs.Radio(["Fun", "Serious", "Professional", "Upset"], label="Choose the chatbot's mood") | |
], | |
outputs="text", | |
title="Gemini Chatbot with Mood Options", | |
description="Chat with the Gemini AI-powered chatbot! Choose the mood for the response." | |
) | |
iface.launch() | |