alperall commited on
Commit
4f5b2da
·
verified ·
1 Parent(s): 56c42d2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +81 -29
app.py CHANGED
@@ -1,46 +1,98 @@
 
1
  import gradio as gr
2
- import requests
3
 
4
- # Prompt dosyasını al
5
- prompt_url = "https://raw.githubusercontent.com/ALPERALL/AlpDroid/refs/heads/main/prompt.txt"
6
- prompt_text = requests.get(prompt_url).text
7
 
8
- # Bot cevabı
9
- def alp_droid_bot(user_input, history):
10
- response = f"{prompt_text}\n\nKullanıcı: {user_input}\nAlpDroid:"
11
- return response
 
 
12
 
13
- # Butonla geçiş fonksiyonu (parametre istemiyor artık)
14
- def start_chat():
15
- return gr.update(visible=False), gr.update(visible=True)
16
 
17
- # Arayüz
18
- with gr.Blocks() as interface:
19
- # Açılış sayfası
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
  with gr.Group(visible=True) as intro_page:
21
  gr.Markdown("""
22
  ## ❗ Kullanım Şartları ve Sorumluluk Reddi
23
 
24
- **AlpDroid**, ALPERALL tarafından geliştirilen deneysel bir yapay zeka karakteridir. Bu bot:
25
-
26
- - Gerçek bir kişi değildir.
27
- - Verdiği yanıtlar sadece eğlence ve deneysel amaçlıdır.
28
- - **Hukuki, tıbbi, finansal veya etik sorumluluk kabul etmez.**
29
- - Kullanıcı, yazılanları kendi sorumluluğunda yorumlar ve uygular.
30
 
31
- Bu botu kullanarak bu şartları **kabul etmiş sayılırsınız.**
32
  """)
33
- accept_btn = gr.Button("✅ Kabul Ediyorum ve Devam Et")
 
34
 
35
- # Sohbet sayfası
36
  with gr.Group(visible=False) as chat_page:
37
  gr.ChatInterface(
38
- fn=alp_droid_bot,
39
- title="🤖 AlpDroid'e Hoş Geldin",
40
- description="ALPERALL tarafından geliştirilen yapay zeka karakteri.",
 
 
 
 
 
 
 
 
 
41
  )
42
 
43
- # Buton tıklanınca geçiş
44
- accept_btn.click(fn=start_chat, inputs=[], outputs=[intro_page, chat_page])
45
 
46
- interface.launch()
 
1
+ from huggingface_hub import InferenceClient
2
  import gradio as gr
 
3
 
4
+ client = InferenceClient("mistralai/Mistral-7B-Instruct-v0.3")
 
 
5
 
6
+ def format_prompt(message, history):
7
+ prompt = "<s>"
8
+ for user_prompt, bot_response in history:
9
+ prompt += f"[INST] {user_prompt} [/INST]{bot_response}</s>"
10
+ prompt += f"[INST] {message} [/INST]"
11
+ return prompt
12
 
13
+ def generate(message, history, file=None, temperature=0.9, max_new_tokens=256, top_p=0.95, repetition_penalty=1.2):
14
+ temperature = float(max(temperature, 1e-2))
15
+ top_p = float(top_p)
16
 
17
+ # Eğer kullanıcı dosya eklediyse, dosya içeriğini mesaja ekle
18
+ if file is not None:
19
+ try:
20
+ file_content = file.read().decode("utf-8")
21
+ message = f"{message}\n\nEkli dosyanın içeriği:\n{file_content}"
22
+ except Exception as e:
23
+ message = f"{message}\n\n(Dosyayı okuyamadım: {str(e)})"
24
+
25
+ formatted_prompt = format_prompt(message, history)
26
+
27
+ stream = client.text_generation(
28
+ formatted_prompt,
29
+ temperature=temperature,
30
+ max_new_tokens=max_new_tokens,
31
+ top_p=top_p,
32
+ repetition_penalty=repetition_penalty,
33
+ do_sample=True,
34
+ seed=42,
35
+ stream=True,
36
+ details=True,
37
+ return_full_text=False,
38
+ )
39
+
40
+ output = ""
41
+ for response in stream:
42
+ output += response.token.text
43
+ yield output
44
+ return output
45
+
46
+ # Ayarlar (slider'lar)
47
+ additional_inputs = [
48
+ gr.Slider(label="Temperature", value=0.9, minimum=0.0, maximum=1.0, step=0.05),
49
+ gr.Slider(label="Max new tokens", value=256, minimum=0, maximum=1024, step=64),
50
+ gr.Slider(label="Top-p (nucleus sampling)", value=0.9, minimum=0.0, maximum=1.0, step=0.05),
51
+ gr.Slider(label="Repetition penalty", value=1.2, minimum=1.0, maximum=2.0, step=0.05),
52
+ ]
53
+
54
+ # Giriş ekranı
55
+ def start_chat(checkbox_state):
56
+ if checkbox_state:
57
+ return gr.update(visible=False), gr.update(visible=True)
58
+ else:
59
+ raise gr.Error("Devam etmek için kutucuğu işaretlemeniz gerekiyor!")
60
+
61
+ # Arayüz başlatma
62
+ with gr.Blocks(theme="Nymbo/Alyx_Theme") as app:
63
+ # Giriş sayfası
64
  with gr.Group(visible=True) as intro_page:
65
  gr.Markdown("""
66
  ## ❗ Kullanım Şartları ve Sorumluluk Reddi
67
 
68
+ **AlpDroid**, ALPERALL tarafından geliştirilen deneysel bir yapay zeka karakteridir.
69
+ - Yapay zekadır, tavsiyeleri bağlayıcı değildir
70
+ - Bilgi eğlence amaçlıdır
71
+ - Sorumluluk kullanıcıya aittir
 
 
72
 
73
+ Devam etmek için aşağıdaki kutucuğu işaretle.
74
  """)
75
+ checkbox = gr.Checkbox(label="✅ Okudum, Onaylıyorum")
76
+ btn = gr.Button("🚀 Devam Et")
77
 
78
+ # Chat ekranı
79
  with gr.Group(visible=False) as chat_page:
80
  gr.ChatInterface(
81
+ fn=generate,
82
+ chatbot=gr.Chatbot(
83
+ show_label=False,
84
+ show_share_button=False,
85
+ show_copy_button=True,
86
+ likeable=True,
87
+ layout="panel"
88
+ ),
89
+ additional_inputs=additional_inputs,
90
+ title="📎 AlpDroid Mistral Chat",
91
+ description="Ataç ile dosya gönder, konuşmaya dahil et.",
92
+ inputs=[gr.Textbox(placeholder="Mesajını yaz..."), gr.File(label="📎 Dosya yükle", file_types=[".txt", ".md", ".csv", ".json"])],
93
  )
94
 
95
+ # Geçiş
96
+ btn.click(fn=start_chat, inputs=[checkbox], outputs=[intro_page, chat_page])
97
 
98
+ app.launch()