File size: 1,331 Bytes
4b9bbd9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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()