File size: 695 Bytes
90ba62d
0b66c85
90ba62d
af14490
025da1c
0b66c85
90ba62d
 
025da1c
0e66e48
025da1c
90ba62d
025da1c
0b66c85
 
 
90ba62d
 
 
025da1c
 
90ba62d
 
 
0b66c85
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
import gradio as gr
import google.generativeai as genai
import os

# Set up Gemini API key
api_key = os.getenv("GEMINI_API_KEY")

def chat_with_ai(prompt):
    """Simple chatbot using Google's Gemini AI."""
    if not api_key:
        return "Error: API key missing. Set GEMINI_API_KEY in Hugging Face secrets."
    try:
        genai.configure(api_key=api_key)
        model = genai.GenerativeModel("gemini-pro")
        response = model.generate_content(prompt)
        return response.text
    except Exception as e:
        return f"Error: {str(e)}"

# Create Gradio chatbot interface
iface = gr.ChatInterface(fn=chat_with_ai)

# Launch the app
if __name__ == "__main__":
    iface.launch()