Download app.py from rizalsaad/chatbot: direct link, hf CLI and curl.
- Browser
- Download file 654 Bytes
-
https://huggingface.co/spaces/rizalsaad/chatbot/resolve/main/app.py
- Command line
-
hf download hf://spaces/rizalsaad/chatbot/app.py
-
curl -L -o app.py https://huggingface.co/spaces/rizalsaad/chatbot/resolve/main/app.py
654 Bytes
| import gradio as gr | |
| import google.generativeai as genai | |
| import os | |
| # Replace with your actual Gemini API key | |
| API_KEY = "AIzaSyBo8ZumjaR32q-wm-75lXxceQkhc5xZMmE" | |
| genai.configure(api_key=API_KEY) | |
| # Initialize the model | |
| model = genai.GenerativeModel("gemini-2.0-flash") | |
| # Function to handle chat | |
| def chat_with_gemini(message, history): | |
| try: | |
| response = model.generate_content(message) | |
| return response.text | |
| except Exception as e: | |
| return f"❌ Error: {str(e)}" | |
| # Gradio interface | |
| gr.ChatInterface( | |
| fn=chat_with_gemini, | |
| title="Gemini Chatbot", | |
| description="Ask me anything!", | |
| theme="soft" | |
| ).launch(debug=True) | |