Spaces:
Runtime error
Runtime error
Upload index.py
Browse files
index.py
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import google.generativeai as genai
|
| 3 |
+
from dotenv import load_dotenv
|
| 4 |
+
import os
|
| 5 |
+
|
| 6 |
+
load_dotenv()
|
| 7 |
+
|
| 8 |
+
genai.configure(api_key=os.getenv("GEMINI_API"))
|
| 9 |
+
model = genai.GenerativeModel('gemini-3-flash-preview')
|
| 10 |
+
|
| 11 |
+
conversation_history = []
|
| 12 |
+
|
| 13 |
+
def chat(message, history):
|
| 14 |
+
conversation_history.append({"role": "user", "parts": [message]})
|
| 15 |
+
try:
|
| 16 |
+
response = model.generate_content(conversation_history)
|
| 17 |
+
conversation_history.append({"role": "model", "parts": [response.text]})
|
| 18 |
+
return response.text
|
| 19 |
+
except Exception as e:
|
| 20 |
+
conversation_history.pop() # Remove the failed user message
|
| 21 |
+
return f"Error: {str(e)}"
|
| 22 |
+
|
| 23 |
+
demo = gr.ChatInterface(
|
| 24 |
+
fn=chat,
|
| 25 |
+
title="Jolie AI Chatbot",
|
| 26 |
+
description="Ask anything you want",
|
| 27 |
+
examples=["Hello", "What is Python", "What happens in Middle East?"],
|
| 28 |
+
|
| 29 |
+
)
|
| 30 |
+
demo.launch(share=True)
|