Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,81 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from huggingface_hub import InferenceClient
|
3 |
+
|
4 |
+
client = InferenceClient("Qwen/Qwen2.5-Coder-32B-Instruct")
|
5 |
+
|
6 |
+
def respond(
|
7 |
+
message,
|
8 |
+
history: list[tuple[str, str]],
|
9 |
+
system_message,
|
10 |
+
max_tokens,
|
11 |
+
temperature,
|
12 |
+
top_p,
|
13 |
+
):
|
14 |
+
messages = [{"role": "system", "content": system_message}]
|
15 |
+
|
16 |
+
for val in history:
|
17 |
+
if val[0]:
|
18 |
+
messages.append({"role": "user", "content": val[0]})
|
19 |
+
if val[1]:
|
20 |
+
messages.append({"role": "assistant", "content": val[1]})
|
21 |
+
|
22 |
+
messages.append({"role": "user", "content": message})
|
23 |
+
|
24 |
+
response = ""
|
25 |
+
|
26 |
+
for message in client.chat_completion(
|
27 |
+
messages,
|
28 |
+
max_tokens=max_tokens,
|
29 |
+
stream=True,
|
30 |
+
temperature=temperature,
|
31 |
+
top_p=top_p,
|
32 |
+
):
|
33 |
+
token = message.choices[0].delta.content
|
34 |
+
|
35 |
+
response += token
|
36 |
+
yield response
|
37 |
+
|
38 |
+
# Custom CSS to change the title color and add logo
|
39 |
+
opq = """
|
40 |
+
.gradio-container h1 {
|
41 |
+
color: #6495ED !important;
|
42 |
+
display: flex;
|
43 |
+
align-items: center;
|
44 |
+
}
|
45 |
+
"""
|
46 |
+
|
47 |
+
# Custom HTML to inject the logo
|
48 |
+
custom_html = """
|
49 |
+
<div>
|
50 |
+
<h1> Welcome to Rxple Chat Bot 💬</h1>
|
51 |
+
</div>
|
52 |
+
"""
|
53 |
+
|
54 |
+
# Combined description with new lines
|
55 |
+
combined_description = """
|
56 |
+
Ghar ka ai this AI does not store any data you can use as much you want without logging<br>
|
57 |
+
-- Follow us on [Instagram](https://www.instagram.com/khellon_patel_21) --
|
58 |
+
"""
|
59 |
+
|
60 |
+
# Use the custom_html for the title
|
61 |
+
demo = gr.ChatInterface(
|
62 |
+
respond,
|
63 |
+
title=custom_html, # Use the custom HTML for the title
|
64 |
+
description=combined_description,
|
65 |
+
additional_inputs=[
|
66 |
+
gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
|
67 |
+
gr.Slider(minimum=1, maximum=2048, value=2048, step=1, label="Max new tokens"),
|
68 |
+
gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
|
69 |
+
gr.Slider(
|
70 |
+
minimum=0.1,
|
71 |
+
maximum=1.0,
|
72 |
+
value=0.95,
|
73 |
+
step=0.05,
|
74 |
+
label="Top-p (nucleus sampling)",
|
75 |
+
),
|
76 |
+
],
|
77 |
+
css=opq # Add the custom CSS here
|
78 |
+
)
|
79 |
+
|
80 |
+
if __name__ == "__main__":
|
81 |
+
demo.launch(share=True)
|