alperall commited on
Commit
6ebb432
·
verified ·
1 Parent(s): 155f07b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -15
app.py CHANGED
@@ -5,10 +5,9 @@ from huggingface_hub import InferenceClient
5
  # HuggingFace modeli
6
  client = InferenceClient("Qwen/Qwen3-32B")
7
 
8
- # GitHub'dan sistem mesajı çekeceğimiz bağlantı
9
  GITHUB_RAW_URL = "https://raw.githubusercontent.com/ALPERALL/AlpDroid/main/prompt.txt"
10
 
11
- # Sistem mesajını GitHub'dan çeken fonksiyon
12
  def fetch_system_message():
13
  try:
14
  response = requests.get(GITHUB_RAW_URL)
@@ -17,20 +16,18 @@ def fetch_system_message():
17
  except requests.exceptions.RequestException as e:
18
  return f"Error fetching system message: {str(e)}"
19
 
20
- # Kullanıcının yazdığı mesaja yanıt oluşturan fonksiyon
21
  def respond(message, history):
22
  max_tokens = 512
23
  temperature = 0.7
24
  top_p = 0.95
25
 
26
- # Sistem mesajı çekiliyor
27
  system_message = fetch_system_message()
28
  if system_message.startswith("Error"):
29
  yield system_message
30
  return
31
 
32
  messages = [{"role": "system", "content": system_message}]
33
-
34
  for val in history:
35
  if val[0]:
36
  messages.append({"role": "user", "content": val[0]})
@@ -38,7 +35,6 @@ def respond(message, history):
38
  messages.append({"role": "assistant", "content": val[1]})
39
 
40
  messages.append({"role": "user", "content": message})
41
-
42
  response = ""
43
 
44
  for message in client.chat_completion(
@@ -52,7 +48,7 @@ def respond(message, history):
52
  response += token
53
  yield response
54
 
55
- # Tema tanımı (mor renk ve özel yazı tipi ile)
56
  theme = gr.themes.Soft(
57
  primary_hue="purple",
58
  secondary_hue="purple",
@@ -77,14 +73,39 @@ theme = gr.themes.Soft(
77
  code_background_fill_dark="#0d1117",
78
  )
79
 
80
- # Gradio arayüzü (dosya yükleme aktif)
81
- demo = gr.ChatInterface(
82
- respond,
83
- upload_files=True, # 🔥 Dosya yükleme tuşunu aktif eder
84
- textbox=gr.Textbox(placeholder="Ask me anything. You can also drop in images and .mp4 videos."),
85
- theme=theme,
86
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
87
 
88
- # Uygulama çalıştırılıyor
89
  if __name__ == "__main__":
90
  demo.launch(share=True)
 
5
  # HuggingFace modeli
6
  client = InferenceClient("Qwen/Qwen3-32B")
7
 
8
+ # Sistem mesajı GitHub'dan alınacak
9
  GITHUB_RAW_URL = "https://raw.githubusercontent.com/ALPERALL/AlpDroid/main/prompt.txt"
10
 
 
11
  def fetch_system_message():
12
  try:
13
  response = requests.get(GITHUB_RAW_URL)
 
16
  except requests.exceptions.RequestException as e:
17
  return f"Error fetching system message: {str(e)}"
18
 
19
+ # Mesaja cevap oluşturan fonksiyon
20
  def respond(message, history):
21
  max_tokens = 512
22
  temperature = 0.7
23
  top_p = 0.95
24
 
 
25
  system_message = fetch_system_message()
26
  if system_message.startswith("Error"):
27
  yield system_message
28
  return
29
 
30
  messages = [{"role": "system", "content": system_message}]
 
31
  for val in history:
32
  if val[0]:
33
  messages.append({"role": "user", "content": val[0]})
 
35
  messages.append({"role": "assistant", "content": val[1]})
36
 
37
  messages.append({"role": "user", "content": message})
 
38
  response = ""
39
 
40
  for message in client.chat_completion(
 
48
  response += token
49
  yield response
50
 
51
+ # Tema (mor renkli koyu mod)
52
  theme = gr.themes.Soft(
53
  primary_hue="purple",
54
  secondary_hue="purple",
 
73
  code_background_fill_dark="#0d1117",
74
  )
75
 
76
+ # Arayüz oluşturuluyor
77
+ with gr.Blocks(theme=theme) as demo:
78
+ gr.Markdown("## 🤖 AlpDroid ChatBot\nMor temalı, dosya destekli güçlü sohbet yardımcınız.")
79
+
80
+ chatbot = gr.Chatbot(label="AlpDroid")
81
+ state = gr.State([])
82
+
83
+ with gr.Row():
84
+ txt = gr.Textbox(
85
+ show_label=False,
86
+ placeholder="Mesaj yaz veya dosya yükle...",
87
+ scale=4
88
+ )
89
+ submit = gr.Button("Gönder", scale=1)
90
+
91
+ with gr.Row():
92
+ file_upload = gr.File(label="Dosya Yükle", file_types=["image", "video", ".pdf", ".txt"], file_count="single")
93
+
94
+ def user_submit(message, file, history):
95
+ if file is not None:
96
+ message = f"Kullanıcı bir dosya gönderdi: {file.name}\nMesaj: {message}"
97
+
98
+ history = history or []
99
+ response_gen = respond(message, history)
100
+ response = ""
101
+ for token in response_gen:
102
+ response = token
103
+ history.append((message, response))
104
+ return history, "", None # textbox'ı ve dosya input'u temizle
105
+
106
+ submit.click(fn=user_submit, inputs=[txt, file_upload, state], outputs=[chatbot, txt, file_upload])
107
+ txt.submit(fn=user_submit, inputs=[txt, file_upload, state], outputs=[chatbot, txt, file_upload])
108
 
109
+ # Uygulama başlatılıyor
110
  if __name__ == "__main__":
111
  demo.launch(share=True)