prithivMLmods
commited on
Commit
•
9240e91
1
Parent(s):
ceec427
Update app.py
Browse files
app.py
CHANGED
@@ -1,73 +1,101 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
import
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
73 |
demo.launch()
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from openai import OpenAI
|
3 |
+
import os
|
4 |
+
|
5 |
+
# Custom CSS for the Deadpool theme
|
6 |
+
css = '''
|
7 |
+
.gradio-container {
|
8 |
+
max-width: 1000px !important;
|
9 |
+
background-color: black !important;
|
10 |
+
color: red !important;
|
11 |
+
font-family: 'Courier New', monospace !important;
|
12 |
+
padding: 20px !important;
|
13 |
+
border-radius: 5px !important;
|
14 |
+
}
|
15 |
+
h1 {
|
16 |
+
text-align: center;
|
17 |
+
color: red !important;
|
18 |
+
font-family: 'Impact', sans-serif !important;
|
19 |
+
}
|
20 |
+
footer {
|
21 |
+
visibility: hidden;
|
22 |
+
}
|
23 |
+
textarea, input, select, button {
|
24 |
+
background-color: black !important;
|
25 |
+
color: red !important;
|
26 |
+
border: 2px solid blue !important;
|
27 |
+
font-family: 'Courier New', monospace !important;
|
28 |
+
}
|
29 |
+
button:hover {
|
30 |
+
background-color: blue !important;
|
31 |
+
color: white !important;
|
32 |
+
}
|
33 |
+
.chatbot {
|
34 |
+
background-color: black !important;
|
35 |
+
color: red !important;
|
36 |
+
border: 2px solid blue !important;
|
37 |
+
font-family: 'Courier New', monospace !important;
|
38 |
+
}
|
39 |
+
'''
|
40 |
+
|
41 |
+
ACCESS_TOKEN = os.getenv("HF_TOKEN")
|
42 |
+
|
43 |
+
client = OpenAI(
|
44 |
+
base_url="https://api-inference.huggingface.co/v1/",
|
45 |
+
api_key=ACCESS_TOKEN,
|
46 |
+
)
|
47 |
+
|
48 |
+
def respond(
|
49 |
+
message,
|
50 |
+
history: list[tuple[str, str]],
|
51 |
+
system_message,
|
52 |
+
max_tokens,
|
53 |
+
temperature,
|
54 |
+
top_p,
|
55 |
+
):
|
56 |
+
messages = [{"role": "system", "content": system_message}]
|
57 |
+
|
58 |
+
for val in history:
|
59 |
+
if val[0]:
|
60 |
+
messages.append({"role": "user", "content": val[0]})
|
61 |
+
if val[1]:
|
62 |
+
messages.append({"role": "assistant", "content": val[1]})
|
63 |
+
|
64 |
+
messages.append({"role": "user", "content": message})
|
65 |
+
|
66 |
+
response = ""
|
67 |
+
|
68 |
+
for message in client.chat.completions.create(
|
69 |
+
model="meta-llama/Meta-Llama-3.1-8B-Instruct",
|
70 |
+
max_tokens=max_tokens,
|
71 |
+
stream=True,
|
72 |
+
temperature=temperature,
|
73 |
+
top_p=top_p,
|
74 |
+
messages=messages,
|
75 |
+
):
|
76 |
+
token = message.choices[0].delta.content
|
77 |
+
|
78 |
+
response += token
|
79 |
+
yield response
|
80 |
+
|
81 |
+
demo = gr.ChatInterface(
|
82 |
+
respond,
|
83 |
+
additional_inputs=[
|
84 |
+
gr.Textbox(value="", label="System message", lines=2),
|
85 |
+
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
|
86 |
+
gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
|
87 |
+
gr.Slider(
|
88 |
+
minimum=0.1,
|
89 |
+
maximum=1.0,
|
90 |
+
value=0.95,
|
91 |
+
step=0.05,
|
92 |
+
label="Top-P",
|
93 |
+
),
|
94 |
+
],
|
95 |
+
css=css,
|
96 |
+
title="Deadpool Chat",
|
97 |
+
theme="default"
|
98 |
+
)
|
99 |
+
|
100 |
+
if __name__ == "__main__":
|
101 |
demo.launch()
|