alperall commited on
Commit
2f3653c
·
verified ·
1 Parent(s): af86855

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -111
app.py CHANGED
@@ -1,124 +1,37 @@
1
  import gradio as gr
2
- import requests
3
- from huggingface_hub import InferenceClient
4
-
5
- client = InferenceClient("MiniMaxAI/MiniMax-M1-80k")
6
-
7
- GITHUB_RAW_URL = "https://raw.githubusercontent.com/ALPERALL/AlpDroid/main/prompt.txt"
8
-
9
- def fetch_system_message():
10
- try:
11
- response = requests.get(GITHUB_RAW_URL)
12
- response.raise_for_status()
13
- return response.text.strip()
14
- except requests.exceptions.RequestException as e:
15
- return f"Error fetching system message: {str(e)}"
16
 
17
  def respond(message, history):
18
- max_tokens = 512
19
- temperature = 0.7
20
- top_p = 0.95
21
-
22
- system_message = fetch_system_message()
23
- if system_message.startswith("Error"):
24
- yield system_message
25
- return
26
-
27
- messages = [{"role": "system", "content": system_message}]
28
- for val in history:
29
- if val[0]:
30
- messages.append({"role": "user", "content": val[0]})
31
- if val[1]:
32
- messages.append({"role": "assistant", "content": val[1]})
33
-
34
- messages.append({"role": "user", "content": message})
35
- response = ""
36
-
37
- for message in client.chat_completion(
38
- messages,
39
- max_tokens=max_tokens,
40
- stream=True,
41
- temperature=temperature,
42
- top_p=top_p,
43
- ):
44
- token = message.choices[0].delta.content
45
- response += token
46
- yield response
47
-
48
- theme = gr.themes.Soft(
49
- primary_hue="purple",
50
- secondary_hue="purple",
51
- neutral_hue="gray",
52
- font=[
53
- gr.themes.GoogleFont("Exo"),
54
- "ui-sans-serif",
55
- "system-ui",
56
- "sans-serif"
57
- ]
58
- ).set(
59
- body_background_fill_dark="#010409",
60
- block_background_fill_dark="#010409",
61
- block_border_width="1px",
62
- block_title_background_fill_dark="#1e1c26",
63
- input_background_fill_dark="#161b22",
64
- button_secondary_background_fill_dark="#21262d",
65
- border_color_accent_dark="#2f353c",
66
- border_color_primary_dark="#2f353c",
67
- background_fill_secondary_dark="#010409",
68
- color_accent_soft_dark="transparent",
69
- code_background_fill_dark="#0d1117",
70
- )
71
 
72
  css = """
73
- #input-textbox textarea {
74
- height: 50px !important;
75
- border-radius: 10px 0 0 10px !important;
76
- padding: 10px !important;
77
- font-size: 16px !important;
78
- resize: none !important;
79
  }
80
-
81
- #submit-button {
82
- width: 50px !important;
83
- height: 50px !important;
84
- border-radius: 0 10px 10px 0 !important;
85
- font-size: 24px !important;
86
- padding: 0 !important;
87
  }
88
  """
89
 
90
- with gr.Blocks(theme=theme, css=css) as demo:
91
- gr.Markdown("## 🤖 AlpDroid\nAlper A. tarafından yapıldı, yasadışı kullanımda sorumluluk kullanıcıya aittir.")
92
-
93
- chatbot = gr.Chatbot(label="AlpDroid")
94
- state = gr.State([])
95
-
96
- with gr.Row():
97
- txt = gr.Textbox(
98
- show_label=False,
99
- placeholder="Sohbet etmek için dokun...",
100
- scale=4,
101
- elem_id="input-textbox"
102
- )
103
- submit = gr.Button("⬆️", scale=1, elem_id="submit-button")
104
-
105
- with gr.Row():
106
- file_upload = gr.File(label="Dosya Yükle", file_types=["image", "video", ".pdf", ".txt"], file_count="single")
107
 
108
- def user_submit(message, file, history):
109
- if file is not None:
110
- message = f"Kullanıcı bir dosya gönderdi: {file.name}\nMesaj: {message}"
111
 
112
- history = history or []
113
- response_gen = respond(message, history)
114
- response = ""
115
- for token in response_gen:
116
- response = token
117
- history.append((message, response))
118
- return history, "", None # textbox ve dosya input temizle
119
 
120
- submit.click(fn=user_submit, inputs=[txt, file_upload, state], outputs=[chatbot, txt, file_upload])
121
- txt.submit(fn=user_submit, inputs=[txt, file_upload, state], outputs=[chatbot, txt, file_upload])
 
 
122
 
123
- if __name__ == "__main__":
124
- demo.launch(share=True)
 
1
  import gradio as gr
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
 
3
  def respond(message, history):
4
+ return "Bot: " + message
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
 
6
  css = """
7
+ .gradio-container {
8
+ font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
9
+ background-color: #f0f0f0;
 
 
 
10
  }
11
+ .chatbot {
12
+ height: 500px;
 
 
 
 
 
13
  }
14
  """
15
 
16
+ with gr.Blocks(css=css, theme=gr.themes.Soft()) as demo:
17
+ gr.Markdown("# Modern Chatbot")
18
+ chatbot = gr.Chatbot()
19
+ msg = gr.Textbox(placeholder="Type your message here...")
20
+ clear = gr.Button("Clear")
 
 
 
 
 
 
 
 
 
 
 
 
21
 
22
+ def user_input(message, history):
23
+ history.append((message, None))
24
+ return history
25
 
26
+ def bot_response(history):
27
+ last_user_message = history[-1][0]
28
+ bot_message = "Bot: " + last_user_message
29
+ history[-1] = (last_user_message, bot_message)
30
+ return history
 
 
31
 
32
+ msg.submit(user_input, [msg, chatbot], [chatbot]).then(
33
+ bot_response, [chatbot], [chatbot]
34
+ )
35
+ clear.click(lambda: [], None, chatbot)
36
 
37
+ demo.launch()