alperall commited on
Commit
70323ec
·
verified ·
1 Parent(s): fc0c78d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -74
app.py CHANGED
@@ -1,99 +1,57 @@
1
- from huggingface_hub import InferenceClient
2
  import gradio as gr
3
 
4
- client = InferenceClient("mistralai/Mistral-7B-Instruct-v0.3")
 
 
 
 
5
 
6
- # Prompt formatlayıcı
7
- def format_prompt(message, history):
8
- prompt = "<s>"
9
- for user_prompt, bot_response in history:
10
- prompt += f"[INST] {user_prompt} [/INST]{bot_response}</s>"
11
- prompt += f"[INST] {message} [/INST]"
12
- return prompt
13
-
14
- # Modelden cevap üret
15
- def generate(message, history, file, temperature, max_new_tokens, top_p, repetition_penalty):
16
- if file:
17
- try:
18
- file_content = file.read().decode("utf-8")
19
- message += f"\n\n📎 Dosya içeriği:\n{file_content}"
20
- except Exception as e:
21
- message += f"\n\n📎 (Dosya okunamadı: {str(e)})"
22
-
23
- prompt = format_prompt(message, history)
24
-
25
- stream = client.text_generation(
26
- prompt,
27
- temperature=temperature,
28
- max_new_tokens=max_new_tokens,
29
- top_p=top_p,
30
- repetition_penalty=repetition_penalty,
31
- do_sample=True,
32
- seed=42,
33
- stream=True,
34
- details=True,
35
- return_full_text=False
36
- )
37
-
38
- output = ""
39
- for response in stream:
40
- output += response.token.text
41
- yield output
42
-
43
- # Kullanıcı onayı kontrolü
44
  def start_chat(approved):
45
  if approved:
46
  return gr.update(visible=False), gr.update(visible=True)
47
  else:
48
- raise gr.Error("Kutucuğu işaretlemeden devam edemezsin Patron!")
49
 
50
- # Arayüz
51
- with gr.Blocks(theme="Nymbo/Alyx_Theme") as app:
52
- # Giriş ekranı
53
  with gr.Group(visible=True) as intro:
54
  gr.Markdown("""
55
- ## 📜 Kullanım Şartları ve Sorumluluk Reddi
56
 
57
- Bu uygulama deneysel bir yapay zekâ içerir.
58
- Tıbbi, hukuki, etik veya finansal tavsiye vermez.
59
- Tüm sorumluluk kullanıcıya aittir.
60
 
61
- Devam etmek için kutucuğu işaretleyin.
62
  """)
63
- agree = gr.Checkbox(label="✅ Okudum, Onaylıyorum")
64
- start_btn = gr.Button("🚀 Başla")
65
 
66
  # Chat ekranı
67
- with gr.Group(visible=False) as chat:
68
- chatbot = gr.Chatbot(label="🧠 AlpDroid", show_label=False)
69
- with gr.Row():
70
- user_input = gr.Textbox(placeholder="Mesajını yaz...", scale=4)
71
- file_upload = gr.File(label="📎", file_types=[".txt", ".csv", ".md", ".json"], scale=1)
72
- send_btn = gr.Button("Gönder")
73
 
74
- # Ayarlar
75
- with gr.Accordion("Ayarlar", open=False):
76
- temperature = gr.Slider(0.1, 1.0, value=0.9, label="🔥 Temperature")
77
- max_new_tokens = gr.Slider(64, 1024, value=256, step=64, label="🧠 Max New Tokens")
78
- top_p = gr.Slider(0.1, 1.0, value=0.95, label="🎯 Top-p")
79
- repetition_penalty = gr.Slider(1.0, 2.0, value=1.2, label="🔁 Repetition Penalty")
80
 
81
- # Geçmiş
82
  state = gr.State([])
83
 
84
- def user_submit(msg, history):
85
- history = history + [[msg, None]]
86
  return "", history
87
 
88
- def bot_response(history, file, temperature, max_new_tokens, top_p, repetition_penalty):
89
- message = history[-1][0]
90
- response = generate(message, history[:-1], file, temperature, max_new_tokens, top_p, repetition_penalty)
91
- return chatbot.stream(response, history, message_index=-1)
92
 
93
- send_btn.click(fn=user_submit, inputs=[user_input, state], outputs=[user_input, state])
94
- send_btn.click(fn=bot_response, inputs=[state, file_upload, temperature, max_new_tokens, top_p, repetition_penalty], outputs=[chatbot, state])
95
 
96
- # Giriş ekranından chate geçiş
97
- start_btn.click(fn=start_chat, inputs=[agree], outputs=[intro, chat])
98
 
99
  app.launch()
 
 
1
  import gradio as gr
2
 
3
+ # MiniMax AI modeli yükleniyor
4
+ chat = gr.load(
5
+ "models/MiniMaxAI/MiniMax-M1-80k",
6
+ provider="novita"
7
+ )
8
 
9
+ # Giriş ekranı kontrolü
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
  def start_chat(approved):
11
  if approved:
12
  return gr.update(visible=False), gr.update(visible=True)
13
  else:
14
+ raise gr.Error("Başlamak için kutucuğu işaretlemelisin Patron!")
15
 
16
+ # Gradio uygulaması
17
+ with gr.Blocks(theme=gr.themes.Base(primary_hue="purple", dark_mode=True)) as app:
18
+ # Giriş sayfası
19
  with gr.Group(visible=True) as intro:
20
  gr.Markdown("""
21
+ ## 🧠 AlpDroid'e Hoş Geldin!
22
 
23
+ Bu yapay zekâ tamamen deneysel amaçlıdır.
24
+ Tıbbi, hukuki, finansal ya da etik kararlar için **kullanılamaz**.
25
+ Kullanım tümüyle senin sorumluluğundadır Patron.
26
 
27
+ Devam etmek için onay kutusunu işaretle.
28
  """)
29
+ approved = gr.Checkbox(label="✅ Okudum, Onaylıyorum")
30
+ begin_btn = gr.Button("🚀 Sohbete Başla")
31
 
32
  # Chat ekranı
33
+ with gr.Group(visible=False) as chat_section:
34
+ chatbot = gr.Chatbot(label="🤖 AlpDroid", show_label=False)
35
+ msg = gr.Textbox(placeholder="Bir mesaj yaz...", scale=4)
36
+ send = gr.Button("Gönder")
 
 
37
 
38
+ # Kullanıcı dosya eklemek isterse diye, altta bir kutu
39
+ file = gr.File(label="📎 Ek dosya (isteğe bağlı)", file_types=[".txt", ".csv", ".json", ".md"])
 
 
 
 
40
 
41
+ # Chat geçmişi yönetimi
42
  state = gr.State([])
43
 
44
+ def user_submit(message, history):
45
+ history = history + [[message, None]]
46
  return "", history
47
 
48
+ def model_response(history, file):
49
+ return chat(history=history)
 
 
50
 
51
+ send.click(fn=user_submit, inputs=[msg, state], outputs=[msg, state])
52
+ send.click(fn=model_response, inputs=[state, file], outputs=[chatbot])
53
 
54
+ # Girişten sohbete geçiş
55
+ begin_btn.click(fn=start_chat, inputs=[approved], outputs=[intro, chat_section])
56
 
57
  app.launch()