Spaces:
Runtime error
Runtime error
File size: 2,650 Bytes
f44789d | 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 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 | from dotenv import load_dotenv
load_dotenv()
import os
from smolagents import CodeAgent
import gradio as gr
from tools.add_events import add_calendar_event
from tools.delete_event import delete_calendar_event
from tools.get_events import get_calendar_events
from tools.mail_sender import send_calendar_via_email
from tools.search_events import search_calendar_events
from models.groq_model import GroqModel
# Groq API anahtarını ortam değişkeninden al
groq_api_key = os.environ.get("GROQ_API_KEY")
if not groq_api_key:
raise ValueError("GROQ_API_KEY ortam değişkeni tanımlı değil.")
# Groq Modelini başlat
groq_model = GroqModel(api_key=groq_api_key)
# CodeAgent'ı araçlar ve model ile oluştur
calendar_agent = CodeAgent(
tools=[add_calendar_event, delete_calendar_event, get_calendar_events, send_calendar_via_email, search_calendar_events],
model=groq_model,
max_steps=5 # İhtiyaca göre ayarlanabilir.
)
def process_message(message, history):
"""Kullanıcının mesajını alıp agent'a gönderir ve yanıtı döndürür."""
try:
agent_response = calendar_agent.run(message)
history.append((message, agent_response))
except Exception as e:
history.append((message, f"Bir hata oluştu: {e}"))
return history, ""
def create_interface():
with gr.Blocks(title="Takvim Asistanı") as demo:
gr.Markdown("# 📅 Takvim Asistanı")
gr.Markdown("""
Bu asistan Google Calendar'ınızı doğal dil komutlarıyla yönetmenize olanak tanır.
**Örnek komutlar:**
- "Bugünkü programımı göster"
- "Yarın saat 14:00'da toplantı ekle"
- "12 Mayıs günü ne var?"
- "Gelecek hafta Pazartesi 10:00-11:30 arası doktor randevusu ekle"
""")
chatbot = gr.Chatbot(height=500)
msg = gr.Textbox(placeholder="Takvim asistanınıza sorun veya istekte bulunun...",
label="Mesajınız")
clear = gr.Button("Temizle")
msg.submit(process_message, [msg, chatbot], [chatbot, msg], queue=True)
clear.click(lambda: None, None, chatbot, queue=False)
# Örnek komutlar için hızlı butonlar
example_buttons = [
"Bugünkü programımı göster",
"Yarın ne var?",
"Pazartesi toplantı ekle, saat 15:00'da",
"12 Mayıs günü etkinliklerimi göster"
]
gr.Examples(
examples=example_buttons,
inputs=msg
)
return demo
if __name__ == '__main__':
# Arayüzü oluştur ve başlat
demo = create_interface()
demo.launch(share=True) |