Zenkad commited on
Commit
cf4739c
·
verified ·
1 Parent(s): fcd8722

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +47 -0
  2. requirements.txt.txt +0 -0
app.py ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os, requests, gradio as gr
2
+
3
+ API_URL = "https://api-inference.huggingface.co/models/mistralai/Mixtral-8x7B-Instruct-v0.1"
4
+ HF_TOKEN = os.getenv("HF_TOKEN")
5
+ HEADERS = {"Authorization": f"Bearer {HF_TOKEN}"}
6
+
7
+ def chat(message, history):
8
+ history = history or []
9
+ convo = [{"role":"system","content":"You are ZenkaMind, a helpful Turkish AI assistant."}]
10
+ for human, ai in history:
11
+ convo += [{"role":"user","content":human},{"role":"assistant","content":ai}]
12
+ convo.append({"role":"user","content":message})
13
+
14
+ payload = {"inputs": convo, "parameters":{"max_new_tokens":300,"temperature":0.7}, "options":{"wait_for_model":True}}
15
+ try:
16
+ r = requests.post(API_URL, headers=HEADERS, json=payload, timeout=60)
17
+ data = r.json()
18
+ if isinstance(data, list) and "generated_text" in data[0]:
19
+ reply = data[0]["generated_text"][-1]["content"]
20
+ elif isinstance(data, list) and isinstance(data[0], dict) and "generated_text" in data[0]:
21
+ reply = data[0]["generated_text"]
22
+ else:
23
+ reply = data.get("error","⚠️ Modelden yanıt alınamadı.")
24
+ except Exception as e:
25
+ reply = f"❌ Hata: {e}"
26
+
27
+ history.append((message, reply))
28
+ return history, history
29
+
30
+ theme = gr.themes.Soft(primary_hue="blue", neutral_hue="slate").set(
31
+ body_background_fill="#0f172a",
32
+ block_background_fill="#1e293b",
33
+ block_title_text_color="#38bdf8"
34
+ )
35
+
36
+ with gr.Blocks(theme=theme, title="ZenkaMind v11") as demo:
37
+ gr.Markdown("<h1 style='text-align:center;color:#38bdf8'>🧠 ZenkaMind v11</h1>"
38
+ "<p style='text-align:center;color:#94a3b8'>Türkçe yapay zekâ sohbet asistanı — Mixtral 8x7B</p>")
39
+ chat_ui = gr.Chatbot(height=460, label="ZenkaMind")
40
+ msg = gr.Textbox(placeholder="Mesajınızı yazın ve Enter’a basın…", show_label=False)
41
+ clear = gr.Button("🧹 Temizle")
42
+
43
+ msg.submit(chat, [msg, chat_ui], [chat_ui, chat_ui])
44
+ clear.click(lambda: None, None, chat_ui, queue=False)
45
+
46
+ gr.Markdown("<p style='text-align:center;font-size:12px;color:#64748b'>© 2025 Zenkamind Bilişim & Teknoloji</p>")
47
+ demo.launch()
requirements.txt.txt ADDED
File without changes