Spaces:
Running
Running
abhillubillu
commited on
Commit
•
53b2631
1
Parent(s):
312e99a
Update app.py
Browse files
app.py
CHANGED
@@ -4,7 +4,6 @@ import spaces
|
|
4 |
from transformers import AutoModelForCausalLM, AutoTokenizer, TextIteratorStreamer
|
5 |
from threading import Thread
|
6 |
|
7 |
-
|
8 |
TITLE = '''
|
9 |
<h1 style="text-align: center;">Meta Llama3.1 8B <a href="https://huggingface.co/spaces/ysharma/Chat_with_Meta_llama3_1_8b?duplicate=true" id="duplicate-button"><button style="color:white">Duplicate this Space</button></a></h1>
|
10 |
'''
|
@@ -25,9 +24,8 @@ Built with Llama
|
|
25 |
|
26 |
PLACEHOLDER = """
|
27 |
<div style="padding: 30px; text-align: center; display: flex; flex-direction: column; align-items: center;">
|
28 |
-
<
|
29 |
-
<
|
30 |
-
<p style="font-size: 18px; margin-bottom: 2px; opacity: 0.65;">Ask me anything...</p>
|
31 |
</div>
|
32 |
"""
|
33 |
|
@@ -36,8 +34,8 @@ h1 {
|
|
36 |
text-align: center;
|
37 |
display: block;
|
38 |
display: flex;
|
39 |
-
|
40 |
-
|
41 |
}
|
42 |
|
43 |
#duplicate-button {
|
@@ -48,6 +46,43 @@ h1 {
|
|
48 |
font-size: 1rem;
|
49 |
padding: 3px 5px;
|
50 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
51 |
"""
|
52 |
|
53 |
model_id = "meta-llama/Meta-Llama-3.1-8B-Instruct"
|
@@ -57,7 +92,7 @@ tokenizer = AutoTokenizer.from_pretrained(model_id)
|
|
57 |
model = AutoModelForCausalLM.from_pretrained(model_id, device_map="auto")
|
58 |
terminators = [
|
59 |
tokenizer.eos_token_id,
|
60 |
-
tokenizer.convert_tokens_to_ids("
|
61 |
]
|
62 |
|
63 |
MAX_INPUT_TOKEN_LENGTH = 4096
|
@@ -108,7 +143,6 @@ def chat_llama3_1_8b(message: str,
|
|
108 |
for text in streamer:
|
109 |
outputs.append(text)
|
110 |
yield "".join(outputs)
|
111 |
-
|
112 |
|
113 |
# Gradio block
|
114 |
chatbot=gr.Chatbot(height=450, placeholder=PLACEHOLDER, label='Gradio ChatInterface')
|
@@ -117,7 +151,6 @@ with gr.Blocks(fill_height=True, css=css) as demo:
|
|
117 |
|
118 |
gr.Markdown(TITLE)
|
119 |
gr.Markdown(DESCRIPTION)
|
120 |
-
#gr.DuplicateButton(value="Duplicate Space for private use", elem_id="duplicate-button")
|
121 |
gr.ChatInterface(
|
122 |
fn=chat_llama3_1_8b,
|
123 |
chatbot=chatbot,
|
@@ -154,4 +187,4 @@ with gr.Blocks(fill_height=True, css=css) as demo:
|
|
154 |
gr.Markdown(LICENSE)
|
155 |
|
156 |
if __name__ == "__main__":
|
157 |
-
demo.launch()
|
|
|
4 |
from transformers import AutoModelForCausalLM, AutoTokenizer, TextIteratorStreamer
|
5 |
from threading import Thread
|
6 |
|
|
|
7 |
TITLE = '''
|
8 |
<h1 style="text-align: center;">Meta Llama3.1 8B <a href="https://huggingface.co/spaces/ysharma/Chat_with_Meta_llama3_1_8b?duplicate=true" id="duplicate-button"><button style="color:white">Duplicate this Space</button></a></h1>
|
9 |
'''
|
|
|
24 |
|
25 |
PLACEHOLDER = """
|
26 |
<div style="padding: 30px; text-align: center; display: flex; flex-direction: column; align-items: center;">
|
27 |
+
<h1 style="font-size: 28px; margin-bottom: 2px; opacity: 0.85;">Meta llama3.1</h1>
|
28 |
+
<p style="font-size: 18px; margin-bottom: 2px; opacity: 0.75;">Ask me anything...</p>
|
|
|
29 |
</div>
|
30 |
"""
|
31 |
|
|
|
34 |
text-align: center;
|
35 |
display: block;
|
36 |
display: flex;
|
37 |
+
align-items: center;
|
38 |
+
justify-content: center;
|
39 |
}
|
40 |
|
41 |
#duplicate-button {
|
|
|
46 |
font-size: 1rem;
|
47 |
padding: 3px 5px;
|
48 |
}
|
49 |
+
|
50 |
+
.gradio-container {
|
51 |
+
border: 1px solid #ddd;
|
52 |
+
border-radius: 10px;
|
53 |
+
padding: 20px;
|
54 |
+
box-shadow: 0 4px 8px rgba(0,0,0,0.1);
|
55 |
+
}
|
56 |
+
|
57 |
+
.gradio-chatbot .input-container {
|
58 |
+
border-top: 1px solid #ddd;
|
59 |
+
padding-top: 10px;
|
60 |
+
}
|
61 |
+
|
62 |
+
.gradio-chatbot .input-container textarea {
|
63 |
+
border: 1px solid #ddd;
|
64 |
+
border-radius: 5px;
|
65 |
+
padding: 10px;
|
66 |
+
width: 100%;
|
67 |
+
box-sizing: border-box;
|
68 |
+
resize: none;
|
69 |
+
height: 50px;
|
70 |
+
}
|
71 |
+
|
72 |
+
.gradio-chatbot .message {
|
73 |
+
border-radius: 10px;
|
74 |
+
padding: 10px;
|
75 |
+
margin: 10px 0;
|
76 |
+
box-shadow: 0 4px 8px rgba(0,0,0,0.1);
|
77 |
+
}
|
78 |
+
|
79 |
+
.gradio-chatbot .message.user {
|
80 |
+
background-color: #f5f5f5;
|
81 |
+
}
|
82 |
+
|
83 |
+
.gradio-chatbot .message.assistant {
|
84 |
+
background-color: #e6f7ff;
|
85 |
+
}
|
86 |
"""
|
87 |
|
88 |
model_id = "meta-llama/Meta-Llama-3.1-8B-Instruct"
|
|
|
92 |
model = AutoModelForCausalLM.from_pretrained(model_id, device_map="auto")
|
93 |
terminators = [
|
94 |
tokenizer.eos_token_id,
|
95 |
+
tokenizer.convert_tokens_to_ids("")
|
96 |
]
|
97 |
|
98 |
MAX_INPUT_TOKEN_LENGTH = 4096
|
|
|
143 |
for text in streamer:
|
144 |
outputs.append(text)
|
145 |
yield "".join(outputs)
|
|
|
146 |
|
147 |
# Gradio block
|
148 |
chatbot=gr.Chatbot(height=450, placeholder=PLACEHOLDER, label='Gradio ChatInterface')
|
|
|
151 |
|
152 |
gr.Markdown(TITLE)
|
153 |
gr.Markdown(DESCRIPTION)
|
|
|
154 |
gr.ChatInterface(
|
155 |
fn=chat_llama3_1_8b,
|
156 |
chatbot=chatbot,
|
|
|
187 |
gr.Markdown(LICENSE)
|
188 |
|
189 |
if __name__ == "__main__":
|
190 |
+
demo.launch()
|