bikabey2 commited on
Commit
e86cb65
·
verified ·
1 Parent(s): 21f32b9

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +63 -0
app.py ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import streamlit as st
3
+ from groq import Groq
4
+
5
+ # Streamlit sayfa yapılandırması
6
+ st.set_page_config(
7
+ page_title="Bikabot Aİ",
8
+ page_icon="🤖",
9
+ layout="centered"
10
+ )
11
+
12
+ # Hugging Face Secrets üzerinden API anahtarını al
13
+ GROQ_API_KEY = os.getenv("GROQ_API_KEY")
14
+
15
+ if not GROQ_API_KEY:
16
+ st.error("⚠️ Hata: GROQ_API_KEY eksik! Lütfen Hugging Face Secrets kısmına ekleyin.")
17
+ st.stop()
18
+
19
+ # Groq istemcisini başlat
20
+ client = Groq(api_key=GROQ_API_KEY)
21
+
22
+ # Sohbet geçmişini başlat (eğer henüz yoksa)
23
+ if "chat_history" not in st.session_state:
24
+ st.session_state.chat_history = []
25
+
26
+ # Uygulama başlığı
27
+ st.title("🤖 Bikabot Aİ")
28
+
29
+ # Sohbet geçmişini görüntüle
30
+ for message in st.session_state.chat_history:
31
+ with st.chat_message(message["role"]):
32
+ st.markdown(message["content"])
33
+
34
+ # Kullanıcı girişi
35
+ user_prompt = st.chat_input("Bikabot Aİ'ye bir şeyler sor...")
36
+
37
+ if user_prompt:
38
+ # Kullanıcının mesajını göster ve geçmişe ekle
39
+ st.chat_message("user").markdown(user_prompt)
40
+ st.session_state.chat_history.append({"role": "user", "content": user_prompt})
41
+
42
+ # LLM'e gönderilecek mesajları hazırla
43
+ messages = [
44
+ {"role": "system", "content": "Sen Bikabot Aİ adında yardımsever bir asistansın."},
45
+ *st.session_state.chat_history
46
+ ]
47
+
48
+ try:
49
+ # Yanıtı al
50
+ response = client.chat.completions.create(
51
+ model="llama-3.1-8b-instant",
52
+ messages=messages
53
+ )
54
+
55
+ assistant_response = response.choices[0].message.content
56
+ st.session_state.chat_history.append({"role": "assistant", "content": assistant_response})
57
+
58
+ # Asistanın yanıtını görüntüle
59
+ with st.chat_message("assistant"):
60
+ st.markdown(assistant_response)
61
+
62
+ except Exception as e:
63
+ st.error(f"⚠️ Hata: {str(e)}")