alperall commited on
Commit
1054ab4
·
verified ·
1 Parent(s): 4f7f4f3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -100
app.py CHANGED
@@ -1,100 +0,0 @@
1
- import gradio as gr
2
- import requests
3
- from huggingface_hub import InferenceClient
4
-
5
- client = InferenceClient("mistralai/Mistral-Nemo-Instruct-2407")
6
-
7
- # Sabit GitHub raw URL'si
8
- GITHUB_RAW_URL = "https://raw.githubusercontent.com/ALPERALL/AlpDroid/main/prompt.txt"
9
-
10
-
11
- def fetch_system_message():
12
- """Fetch system message from a GitHub raw link."""
13
- try:
14
- response = requests.get(GITHUB_RAW_URL)
15
- response.raise_for_status()
16
- return response.text.strip()
17
- except requests.exceptions.RequestException as e:
18
- return f"Error fetching system message: {str(e)}"
19
-
20
-
21
- def respond(message, history):
22
- # Sabit parametreler
23
- max_tokens = 512
24
- temperature = 0.7
25
- top_p = 0.95
26
-
27
- # Fetch the system message from GitHub
28
- system_message = fetch_system_message()
29
- if system_message.startswith("Error"):
30
- yield system_message
31
- return
32
-
33
- messages = [{"role": "system", "content": system_message}]
34
-
35
- for val in history:
36
- if val[0]:
37
- messages.append({"role": "user", "content": val[0]})
38
- if val[1]:
39
- messages.append({"role": "assistant", "content": val[1]})
40
-
41
- messages.append({"role": "user", "content": message})
42
-
43
- response = ""
44
-
45
- for message in client.chat_completion(
46
- messages,
47
- max_tokens=max_tokens,
48
- stream=True,
49
- temperature=temperature,
50
- top_p=top_p,
51
- ):
52
- token = message.choices[0].delta.content
53
- response += token
54
- yield response
55
-
56
-
57
- # Koyu tema tanımlama
58
- theme = gr.themes.Soft(
59
- primary_hue="emerald",
60
- secondary_hue="emerald",
61
- neutral_hue="gray",
62
- font=[
63
- gr.themes.GoogleFont("Exo"),
64
- "ui-sans-serif",
65
- "system-ui",
66
- "sans-serif"
67
- ]
68
- ).set(
69
- body_background_fill_dark="#010409",
70
- block_background_fill_dark="#010409",
71
- block_border_width="1px",
72
- block_title_background_fill_dark="#1e1c26",
73
- input_background_fill_dark="#161b22",
74
- button_secondary_background_fill_dark="#21262d",
75
- border_color_accent_dark="#2f353c",
76
- border_color_primary_dark="#2f353c",
77
- background_fill_secondary_dark="#010409",
78
- color_accent_soft_dark="transparent",
79
- code_background_fill_dark="#0d1117",
80
- )
81
-
82
- # Demo başlatılıyor
83
- with gr.Blocks(theme=theme) as demo:
84
- with gr.Row(elem_id="chuanhu-header"):
85
- gr.HTML("<h1>Chatbot Arayüzü</h1>", elem_id="app-title")
86
- status_display = gr.Markdown("Status: Ready", elem_id="status-display")
87
-
88
- with gr.Row(elem_id="chuanhu-body"):
89
- with gr.Column(elem_id="chatbot-area"):
90
- chatbot = gr.Chatbot(label="Chatbot", elem_id="chuanhu-chatbot")
91
- user_input = gr.Textbox(show_label=False, placeholder="Buraya yazın...", elem_id="user-input-tb")
92
- submit_btn = gr.Button("Gönder", variant="primary", elem_id="submit-btn")
93
-
94
- with gr.Row(elem_id="chuanhu-footer"):
95
- gr.Markdown("Chatbot Arayüzü", elem_id="footer")
96
-
97
- submit_btn.click(respond, inputs=[user_input, chatbot], outputs=[chatbot])
98
-
99
- if __name__ == "__main__":
100
- demo.launch(share=True)