nzhabchikov commited on
Commit
477ae0a
ยท
1 Parent(s): 5332792

added vlm model texting

Browse files
Files changed (3) hide show
  1. app.py +62 -49
  2. requirements.txt +3 -1
  3. web_data.py +144 -0
app.py CHANGED
@@ -1,64 +1,77 @@
1
  import gradio as gr
2
- from huggingface_hub import InferenceClient
 
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
- for val in history:
21
- if val[0]:
22
- messages.append({"role": "user", "content": val[0]})
23
- if val[1]:
24
- messages.append({"role": "assistant", "content": val[1]})
 
 
 
 
 
 
 
 
 
 
 
 
 
25
 
26
- messages.append({"role": "user", "content": message})
 
 
 
 
 
27
 
28
- response = ""
 
29
 
30
- for message in client.chat_completion(
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
- For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
45
- """
46
- demo = gr.ChatInterface(
47
- respond,
48
- additional_inputs=[
49
- gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
50
- gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
51
- gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
52
- gr.Slider(
53
- minimum=0.1,
54
- maximum=1.0,
55
- value=0.95,
56
- step=0.05,
57
- label="Top-p (nucleus sampling)",
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
- huggingface_hub==0.25.2
 
 
 
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
+ """