Spaces:
Running
Running
Commit
ยท
477ae0a
1
Parent(s):
5332792
added vlm model texting
Browse files- app.py +62 -49
- requirements.txt +3 -1
- web_data.py +144 -0
app.py
CHANGED
@@ -1,64 +1,77 @@
|
|
1 |
import gradio as gr
|
2 |
-
|
|
|
3 |
|
4 |
-
|
5 |
-
For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
|
6 |
-
"""
|
7 |
-
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
8 |
|
|
|
|
|
|
|
|
|
|
|
9 |
|
10 |
-
def respond(
|
11 |
-
message,
|
12 |
-
history: list[tuple[str, str]],
|
13 |
-
system_message,
|
14 |
-
max_tokens,
|
15 |
-
temperature,
|
16 |
-
top_p,
|
17 |
-
):
|
18 |
-
messages = [{"role": "system", "content": system_message}]
|
19 |
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
|
26 |
-
|
|
|
|
|
|
|
|
|
|
|
27 |
|
28 |
-
|
|
|
29 |
|
30 |
-
|
31 |
-
messages,
|
32 |
-
max_tokens=max_tokens,
|
33 |
-
stream=True,
|
34 |
-
temperature=temperature,
|
35 |
-
top_p=top_p,
|
36 |
-
):
|
37 |
-
token = message.choices[0].delta.content
|
38 |
|
39 |
-
response += token
|
40 |
-
yield response
|
41 |
|
|
|
|
|
|
|
42 |
|
43 |
-
""
|
44 |
-
|
45 |
-
""
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
)
|
|
|
|
|
|
|
|
|
|
|
61 |
|
|
|
62 |
|
63 |
if __name__ == "__main__":
|
64 |
demo.launch()
|
|
|
1 |
import gradio as gr
|
2 |
+
import torch
|
3 |
+
from transformers import AutoProcessor, AutoModelForVision2Seq
|
4 |
|
5 |
+
from web_data import custom_css, header, footer, shortcuts
|
|
|
|
|
|
|
6 |
|
7 |
+
processor = AutoProcessor.from_pretrained("HuggingFaceTB/SmolVLM-256M-Instruct")
|
8 |
+
model = AutoModelForVision2Seq.from_pretrained(
|
9 |
+
"HuggingFaceTB/SmolVLM-256M-Instruct",
|
10 |
+
torch_dtype=torch.bfloat16,
|
11 |
+
)
|
12 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
|
14 |
+
def respond(message, history, image, system_message):
|
15 |
+
messages = [
|
16 |
+
{
|
17 |
+
"role": "system",
|
18 |
+
"content": [
|
19 |
+
{"type": "text", "text": system_message}
|
20 |
+
]
|
21 |
+
},
|
22 |
+
]
|
23 |
+
user_message = {
|
24 |
+
"role": "user",
|
25 |
+
"content": [
|
26 |
+
{"type": "text", "text": message}
|
27 |
+
]
|
28 |
+
}
|
29 |
+
if image:
|
30 |
+
user_message['content'].append({"type": "image"})
|
31 |
+
messages.append(user_message)
|
32 |
|
33 |
+
prompt = processor.apply_chat_template(messages, add_generation_prompt=True)
|
34 |
+
if image:
|
35 |
+
resized_image = image.resize((32, 32))
|
36 |
+
inputs = processor(text=prompt, images=[resized_image], return_tensors="pt")
|
37 |
+
else:
|
38 |
+
inputs = processor(text=prompt, return_tensors="pt")
|
39 |
|
40 |
+
generated_ids = model.generate(**inputs, max_new_tokens=500)
|
41 |
+
generated_texts = processor.batch_decode(generated_ids, skip_special_tokens=True)
|
42 |
|
43 |
+
yield generated_texts[0].split('Assistant:')[1].strip()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
44 |
|
|
|
|
|
45 |
|
46 |
+
# ======the code below this section is pure vibing coding======
|
47 |
+
with gr.Blocks(theme=gr.themes.Glass(), css=custom_css) as demo:
|
48 |
+
gr.HTML(header)
|
49 |
|
50 |
+
with gr.Row(variant="panel"):
|
51 |
+
with gr.Column(scale=1):
|
52 |
+
with gr.Accordion("๐ CONTROL PANEL", open=True):
|
53 |
+
system_message = gr.Textbox(
|
54 |
+
value="You're a cool AI that speaks Gen-Z slang ๐",
|
55 |
+
label="๐ค BOT PERSONALITY",
|
56 |
+
lines=2,
|
57 |
+
max_lines=4,
|
58 |
+
elem_classes="cyber-input"
|
59 |
+
)
|
60 |
+
image_input = gr.Image(
|
61 |
+
type="pil",
|
62 |
+
label="๐ธ UPLOAD PIC",
|
63 |
+
height=200,
|
64 |
+
elem_classes="glow-border"
|
65 |
+
)
|
66 |
+
|
67 |
+
with gr.Column(scale=3):
|
68 |
+
chat_interface = gr.ChatInterface(
|
69 |
+
respond,
|
70 |
+
additional_inputs=[image_input, system_message],
|
71 |
+
submit_btn="๐ค SEND",
|
72 |
+
)
|
73 |
|
74 |
+
gr.HTML(footer)
|
75 |
|
76 |
if __name__ == "__main__":
|
77 |
demo.launch()
|
requirements.txt
CHANGED
@@ -1 +1,3 @@
|
|
1 |
-
|
|
|
|
|
|
1 |
+
gradio==5.25.0
|
2 |
+
transformers==4.51.2
|
3 |
+
torch==2.6.0
|
web_data.py
ADDED
@@ -0,0 +1,144 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
custom_css = """
|
2 |
+
:root {
|
3 |
+
--neon-pink: #ff6bff;
|
4 |
+
--cyber-blue: #00f7ff;
|
5 |
+
--acid-green: #7fff00;
|
6 |
+
--gradient-angle: 135deg;
|
7 |
+
}
|
8 |
+
|
9 |
+
.gradio-container {
|
10 |
+
background: linear-gradient(var(--gradient-angle),
|
11 |
+
#0f0f0f 0%,
|
12 |
+
#1a1a1a 50%,
|
13 |
+
#0f0f0f 100%) !important;
|
14 |
+
font-family: 'Comic Neue', cursive !important;
|
15 |
+
}
|
16 |
+
|
17 |
+
.dark .gradio-container {
|
18 |
+
background: linear-gradient(var(--gradient-angle),
|
19 |
+
#000000 0%,
|
20 |
+
#1a1a1a 100%) !important;
|
21 |
+
}
|
22 |
+
|
23 |
+
.chat-message {
|
24 |
+
padding: 15px 25px !important;
|
25 |
+
border-radius: 30px !important;
|
26 |
+
margin: 15px 0 !important;
|
27 |
+
border: none !important;
|
28 |
+
position: relative;
|
29 |
+
transition: all 0.3s ease !important;
|
30 |
+
max-width: 80% !important;
|
31 |
+
font-size: 1.1em !important;
|
32 |
+
}
|
33 |
+
|
34 |
+
.user-message {
|
35 |
+
background: linear-gradient(45deg, #ff0080, #ff6bff) !important;
|
36 |
+
color: white !important;
|
37 |
+
margin-left: auto !important;
|
38 |
+
box-shadow: 0 4px 15px rgba(255,107,255,0.3) !important;
|
39 |
+
}
|
40 |
+
|
41 |
+
.bot-message {
|
42 |
+
background: linear-gradient(45deg, #00b4d8, #00f7ff) !important;
|
43 |
+
color: black !important;
|
44 |
+
margin-right: auto !important;
|
45 |
+
box-shadow: 0 4px 15px rgba(0,247,255,0.3) !important;
|
46 |
+
}
|
47 |
+
|
48 |
+
.chat-message::after {
|
49 |
+
content: '';
|
50 |
+
position: absolute;
|
51 |
+
top: -2px;
|
52 |
+
left: -2px;
|
53 |
+
right: -2px;
|
54 |
+
bottom: -2px;
|
55 |
+
border-radius: 30px;
|
56 |
+
z-index: -1;
|
57 |
+
background: linear-gradient(45deg,
|
58 |
+
var(--neon-pink),
|
59 |
+
var(--cyber-blue),
|
60 |
+
var(--acid-green));
|
61 |
+
animation: gradient-animation 3s ease infinite;
|
62 |
+
}
|
63 |
+
|
64 |
+
@keyframes gradient-animation {
|
65 |
+
0% { opacity: 0.3; }
|
66 |
+
50% { opacity: 0.7; }
|
67 |
+
100% { opacity: 0.3; }
|
68 |
+
}
|
69 |
+
|
70 |
+
.header-image {
|
71 |
+
width: 150px !important;
|
72 |
+
height: 150px !important;
|
73 |
+
object-fit: cover;
|
74 |
+
border-radius: 50% !important;
|
75 |
+
border: 3px solid var(--neon-pink) !important;
|
76 |
+
box-shadow: 0 0 20px var(--neon-pink) !important;
|
77 |
+
animation: float 4s ease-in-out infinite;
|
78 |
+
}
|
79 |
+
|
80 |
+
@keyframes float {
|
81 |
+
0% { transform: translateY(0px); }
|
82 |
+
50% { transform: translateY(-20px); }
|
83 |
+
100% { transform: translateY(0px); }
|
84 |
+
}
|
85 |
+
|
86 |
+
button {
|
87 |
+
background: linear-gradient(45deg, #7fff00, #00f7ff) !important;
|
88 |
+
border: none !important;
|
89 |
+
border-radius: 15px !important;
|
90 |
+
color: black !important;
|
91 |
+
font-weight: bold !important;
|
92 |
+
text-transform: uppercase !important;
|
93 |
+
transition: all 0.3s ease !important;
|
94 |
+
}
|
95 |
+
|
96 |
+
button:hover {
|
97 |
+
transform: scale(1.05) !important;
|
98 |
+
box-shadow: 0 0 15px var(--acid-green) !important;
|
99 |
+
}
|
100 |
+
|
101 |
+
.gr-examples {
|
102 |
+
border: 2px solid var(--neon-pink) !important;
|
103 |
+
border-radius: 20px !important;
|
104 |
+
background: rgba(0,0,0,0.3) !important;
|
105 |
+
}
|
106 |
+
|
107 |
+
footer {
|
108 |
+
text-align: center !important;
|
109 |
+
color: #fff !important;
|
110 |
+
text-shadow: 0 0 10px var(--cyber-blue) !important;
|
111 |
+
}
|
112 |
+
"""
|
113 |
+
header = """
|
114 |
+
<div style="text-align: center; padding: 20px;">
|
115 |
+
<h1 style="
|
116 |
+
font-family: 'Bebas Neue', cursive;
|
117 |
+
font-size: 3.5em;
|
118 |
+
color: #7fff00;
|
119 |
+
text-shadow: 0 0 15px #7fff00;
|
120 |
+
margin: 0;
|
121 |
+
">
|
122 |
+
VISION.TALK ๐ฎ
|
123 |
+
</h1>
|
124 |
+
<img class="header-image"
|
125 |
+
src="https://cdn-icons-png.flaticon.com/512/7858/7858975.png"
|
126 |
+
alt="Cyber AI">
|
127 |
+
<p style="color: #00f7ff; margin: 10px 0; font-size: 1.2em;">
|
128 |
+
Upload. Chat. Vibing. Repeat. ๐
|
129 |
+
</p>
|
130 |
+
</div>
|
131 |
+
"""
|
132 |
+
footer = """
|
133 |
+
<div class="glitch-wrapper" style="text-align: center; margin-top: 30px;">
|
134 |
+
<p class="glitch" data-text="โ ๏ธ WARNING: AI MAY GENERATE RANDOM VIBES">โ ๏ธ WARNING: AI MAY GENERATE RANDOM VIBES</p>
|
135 |
+
<p style="color: #00f7ff;">๐ Your data stays chill โข ๐จ Made with ~vibes~</p>
|
136 |
+
</div>
|
137 |
+
"""
|
138 |
+
shortcuts = """
|
139 |
+
<div style="text-align: center; margin: 20px 0;">
|
140 |
+
<p style="color: #ff6bff;">๐ฅ QUICK ACTIONS:</p>
|
141 |
+
<button style="margin: 5px;" onclick="document.querySelector('textarea').value='Rate this pic 1-10'">๐พ Rate Pic</button>
|
142 |
+
<button style="margin: 5px;" onclick="document.querySelector('textarea').value='Make this pic go viral'">๐ Viral Content</button>
|
143 |
+
</div>
|
144 |
+
"""
|