Zenkad commited on
Commit
1413a24
·
verified ·
1 Parent(s): f9ec801

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +55 -65
app.py CHANGED
@@ -1,89 +1,79 @@
1
- import os, requests, gradio as gr
 
 
2
 
3
- # 🔗 Modeller
4
- PRIMARY_URL = "https://api-inference.huggingface.co/models/HuggingFaceH4/zephyr-7b-beta"
5
- FALLBACK_URL = "https://api-inference.huggingface.co/models/microsoft/Phi-3-mini-4k-instruct"
6
- HF_TOKEN = os.getenv("HF_TOKEN")
7
  HEADERS = {"Authorization": f"Bearer {HF_TOKEN}"}
8
 
9
- # 🧠 Model bağlantısı
10
- def ask_model(url, message):
 
 
 
 
 
 
 
 
 
11
  payload = {
12
- "inputs": message,
13
  "parameters": {"max_new_tokens": 300, "temperature": 0.7},
14
- "options": {"wait_for_model": True}
15
  }
 
16
  try:
17
- r = requests.post(url, headers=HEADERS, json=payload, timeout=60)
18
  data = r.json()
 
19
  if isinstance(data, list) and "generated_text" in data[0]:
20
- return data[0]["generated_text"]
21
- if isinstance(data, dict) and "generated_text" in data:
22
- return data["generated_text"]
23
- return None
24
- except Exception:
25
- return None
 
26
 
27
- # 💬 Sohbet sistemi
28
- def chat(message, history):
29
- history = history or []
30
- reply = ask_model(PRIMARY_URL, message)
31
- if not reply:
32
- reply = ask_model(FALLBACK_URL, message)
33
- if not reply:
34
- reply = "⚠️ Şu anda modellerden yanıt alınamadı. Lütfen birkaç saniye sonra tekrar deneyin."
35
  history.append((message, reply))
36
  return history, history
37
 
38
- # 💰 Görev paneli simülasyonu
39
- def free_tasks():
40
- return """🎯 **Free Görevler (14 Görev)**
41
- - 4 Reklam İzle → 5₺
42
- - Günlük Giriş → 2₺
43
- - 1 Anket Doldur → 3₺
44
- - 1 Arkadaş Davet Et → 10₺
45
- - Görevleri tamamla, 500₺ olduğunda çekim yap!"""
46
-
47
- def premium_tasks():
48
- return """💎 **Premium Görevler (30 Görev)**
49
- - 5 Reklam İzle → 10₺
50
- - 2 Anket Doldur → 6₺
51
- - Günlük Bonus Görevi → 15₺
52
- - Görevleri tamamla, 500₺ olduğunda çekim yap!
53
- - Premium kullanıcılar 2x kazanç alır!"""
54
 
55
- # 🎨 Tema ayarları
56
- theme = gr.themes.Soft(primary_hue="blue", neutral_hue="slate").set(
 
 
 
57
  body_background_fill="#0f172a",
58
  block_background_fill="#1e293b",
59
- block_title_text_color="#38bdf8"
60
  )
61
 
62
- # 🧱 Arayüz
63
- with gr.Blocks(theme=theme, title="ZenkaMind Platform v1.0") as demo:
64
  gr.Markdown(
65
- "<h1 style='text-align:center;color:#38bdf8'>🧠 ZenkaMind Platform</h1>"
66
- "<p style='text-align:center;color:#94a3b8'>Free & Premium Görev + Yapay Zekâ Asistanı</p>"
 
 
 
 
 
67
  )
68
 
69
- with gr.Row():
70
- with gr.Column(scale=1):
71
- gr.Markdown("### 💼 Görev Paneli")
72
- tab = gr.TabbedInterface(
73
- [gr.Markdown(free_tasks()), gr.Markdown(premium_tasks())],
74
- ["Free Kullanıcılar", "Premium Kullanıcılar"]
75
- )
76
- gr.Markdown("<p style='font-size:14px;color:#94a3b8'>💰 Güncel Kazanç: <b>₺245.00</b></p>")
77
-
78
- with gr.Column(scale=2):
79
- gr.Markdown("### 🤖 ZenkaMind Sohbet Asistanı")
80
- chat_ui = gr.Chatbot(height=460, label="ZenkaMind Chat")
81
- msg = gr.Textbox(placeholder="Mesajınızı yazın ve Enter’a basın…", show_label=False)
82
- clear = gr.Button("🧹 Temizle")
83
-
84
- msg.submit(chat, [msg, chat_ui], [chat_ui, chat_ui])
85
- clear.click(lambda: None, None, chat_ui, queue=False)
86
 
87
- gr.Markdown("<p style='text-align:center;font-size:12px;color:#64748b'>© 2025 ZenkaMind Bilişim & Teknoloji</p>")
 
 
 
88
 
89
  demo.launch()
 
1
+ import os
2
+ import requests
3
+ import gradio as gr
4
 
5
+ # 🔐 Hugging Face API bağlantısı
6
+ API_URL = "https://api-inference.huggingface.co/models/mistralai/Mixtral-8x7B-Instruct-v0.1"
7
+ HF_TOKEN = os.getenv("HF_TOKEN") # Hugging Face Secret olarak ekledin ya, burada çağrılıyor
 
8
  HEADERS = {"Authorization": f"Bearer {HF_TOKEN}"}
9
 
10
+ # 💬 Chat fonksiyonu
11
+ def chat(message, history):
12
+ history = history or []
13
+ convo = [{"role": "system", "content": "You are ZenkaMind, a helpful Turkish AI assistant."}]
14
+
15
+ for user, bot in history:
16
+ convo.append({"role": "user", "content": user})
17
+ convo.append({"role": "assistant", "content": bot})
18
+
19
+ convo.append({"role": "user", "content": message})
20
+
21
  payload = {
22
+ "inputs": convo,
23
  "parameters": {"max_new_tokens": 300, "temperature": 0.7},
24
+ "options": {"wait_for_model": True},
25
  }
26
+
27
  try:
28
+ r = requests.post(API_URL, headers=HEADERS, json=payload, timeout=60)
29
  data = r.json()
30
+
31
  if isinstance(data, list) and "generated_text" in data[0]:
32
+ reply = data[0]["generated_text"]
33
+ elif isinstance(data, dict) and "error" in data:
34
+ reply = f"⚠️ Hata: {data['error']}"
35
+ else:
36
+ reply = "⚠️ Model boş yanıt döndürdü veya bağlantı kesildi."
37
+ except Exception as e:
38
+ reply = f"❌ Sunucu hatası: {str(e)}"
39
 
 
 
 
 
 
 
 
 
40
  history.append((message, reply))
41
  return history, history
42
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
43
 
44
+ # 🎨 Tema ve Arayüz
45
+ theme = gr.themes.Soft(
46
+ primary_hue="blue",
47
+ neutral_hue="slate",
48
+ ).set(
49
  body_background_fill="#0f172a",
50
  block_background_fill="#1e293b",
51
+ block_label_text_color="#38bdf8",
52
  )
53
 
54
+ with gr.Blocks(theme=theme, title="ZenkaMind v12") as demo:
 
55
  gr.Markdown(
56
+ """
57
+ <h1 style="text-align:center;color:#38bdf8;">🧠 ZenkaMind v12</h1>
58
+ <p style="text-align:center;color:#94a3b8;">
59
+ Türkçe yapay zekâ sohbet asistanı — <strong>Mixtral 8x7B</strong> modeliyle çalışır.<br>
60
+ © 2025 ZenkaMind Bilişim & Teknoloji
61
+ </p>
62
+ """
63
  )
64
 
65
+ chatbot = gr.Chatbot(height=500, label="ZenkaMind Sohbet Ekranı")
66
+ user_msg = gr.Textbox(
67
+ placeholder="Mesajınızı yazın ve Enter’a basın...",
68
+ show_label=False,
69
+ autofocus=True,
70
+ )
71
+ send_btn = gr.Button("🚀 Gönder")
72
+ clear_btn = gr.Button("🧹 Sohbeti Temizle")
 
 
 
 
 
 
 
 
 
73
 
74
+ # Bağlantılar
75
+ user_msg.submit(chat, [user_msg, chatbot], [chatbot, chatbot])
76
+ send_btn.click(chat, [user_msg, chatbot], [chatbot, chatbot])
77
+ clear_btn.click(lambda: None, None, chatbot, queue=False)
78
 
79
  demo.launch()