gusreinaos commited on
Commit
9e8c9e9
·
1 Parent(s): 721b975

Change UI and fix API not found

Browse files
Files changed (1) hide show
  1. app.py +90 -194
app.py CHANGED
@@ -26,196 +26,136 @@ llm = Llama(
26
  print("✅ Model loaded!")
27
 
28
  def chat(message, history):
29
- prompt = "<|begin_of_text|>"
 
30
 
31
  for user_msg, bot_msg in history:
32
- prompt += f"<|start_header_id|>user<|end_header_id|>\n\n{user_msg}<|eot_id|>"
33
- prompt += f"<|start_header_id|>assistant<|end_header_id|>\n\n{bot_msg}<|eot_id|>"
34
 
35
- prompt += f"<|start_header_id|>user<|end_header_id|>\n\n{message}<|eot_id|>"
36
- prompt += "<|start_header_id|>assistant<|end_header_id|>\n\n"
37
 
 
38
  response = llm(
39
  prompt,
40
  max_tokens=512,
41
  temperature=0.7,
42
  top_p=0.9,
43
- stop=["<|eot_id|>", "<|start_header_id|>"],
44
  echo=False
45
  )
46
 
47
- bot_response = response['choices'][0]['text'].strip()
48
- history.append((message, bot_response))
49
- return history
50
 
51
- # HACKER STYLE CSS
52
  custom_css = """
53
- @import url('https://fonts.googleapis.com/css2?family=Share+Tech+Mono&family=Orbitron:wght@400;700;900&display=swap');
54
-
55
- /* Matrix background with animated scanlines */
56
- body {
57
- background: #000000 !important;
58
- background-image:
59
- repeating-linear-gradient(
60
- 0deg,
61
- rgba(0, 255, 65, 0.03) 0px,
62
- transparent 1px,
63
- transparent 2px,
64
- rgba(0, 255, 65, 0.03) 3px
65
- ),
66
- linear-gradient(90deg, #000000 21px, #0a0a0a 1px) !important;
67
- background-size: 100% 3px, 22px 100% !important;
68
- animation: scanlines 8s linear infinite !important;
69
- }
70
 
71
- @keyframes scanlines {
72
- 0% { background-position: 0 0, 0 0; }
73
- 100% { background-position: 0 100%, 0 0; }
 
74
  }
75
 
76
- @keyframes glow {
77
- 0%, 100% { text-shadow: 0 0 10px #00ff41, 0 0 20px #00ff41, 0 0 30px #00ff41; }
78
- 50% { text-shadow: 0 0 20px #00ff41, 0 0 30px #00ff41, 0 0 40px #00ff41; }
 
79
  }
80
 
81
- @keyframes border-glow {
82
- 0%, 100% { box-shadow: 0 0 5px #00ff41, 0 0 10px #00ff41, inset 0 0 5px #00ff41; }
83
- 50% { box-shadow: 0 0 10px #00ff41, 0 0 20px #00ff41, inset 0 0 10px #00ff41; }
 
84
  }
85
 
86
- /* Main container */
87
- .gradio-container {
88
- max-width: 1200px !important;
89
- margin: 0 auto !important;
90
- background: rgba(0, 0, 0, 0.95) !important;
91
- border: 2px solid #00ff41 !important;
92
- box-shadow: 0 0 20px #00ff41, inset 0 0 20px rgba(0, 255, 65, 0.1) !important;
93
- padding: 20px !important;
94
- }
95
-
96
- /* Typography */
97
- * {
98
- font-family: 'Share Tech Mono', monospace !important;
99
- color: #00ff41 !important;
100
  }
101
 
102
- h1, h2, h3, h4, h5, h6 {
103
- font-family: 'Orbitron', monospace !important;
104
- color: #00ff41 !important;
105
- text-transform: uppercase !important;
106
- letter-spacing: 3px !important;
107
- animation: glow 2s ease-in-out infinite !important;
108
  }
109
 
110
- /* Chatbot styling */
111
  .message {
112
- background: rgba(0, 20, 0, 0.8) !important;
113
- border: 1px solid #00ff41 !important;
114
- border-left: 4px solid #00ff41 !important;
115
- color: #00ff41 !important;
116
- padding: 15px !important;
117
- margin: 10px 0 !important;
118
- box-shadow: 0 0 10px rgba(0, 255, 65, 0.3) !important;
119
  }
120
 
121
- .message.user {
122
- border-left: 4px solid #0ff !important;
123
- box-shadow: 0 0 10px rgba(0, 255, 255, 0.3) !important;
124
  }
125
 
126
- .message.bot {
127
- border-left: 4px solid #00ff41 !important;
128
  }
129
 
130
- /* Input fields */
131
  input, textarea {
132
- background: rgba(0, 20, 0, 0.9) !important;
133
- border: 2px solid #00ff41 !important;
134
- color: #00ff41 !important;
135
- font-family: 'Share Tech Mono', monospace !important;
136
- padding: 12px !important;
137
- animation: border-glow 2s ease-in-out infinite !important;
138
  }
139
 
140
  input:focus, textarea:focus {
141
- border: 2px solid #0ff !important;
142
- box-shadow: 0 0 15px #0ff, inset 0 0 15px rgba(0, 255, 255, 0.2) !important;
143
  outline: none !important;
 
144
  }
145
 
146
  input::placeholder, textarea::placeholder {
147
- color: rgba(0, 255, 65, 0.5) !important;
148
  }
149
 
150
  /* Buttons */
151
  button {
152
- background: linear-gradient(135deg, #001a00 0%, #003300 100%) !important;
153
- border: 2px solid #00ff41 !important;
154
- color: #00ff41 !important;
155
- font-family: 'Orbitron', monospace !important;
156
- font-weight: 700 !important;
157
- text-transform: uppercase !important;
158
- letter-spacing: 2px !important;
159
- padding: 12px 24px !important;
160
- transition: all 0.3s ease !important;
161
- box-shadow: 0 0 10px rgba(0, 255, 65, 0.3) !important;
162
  }
163
 
164
  button:hover {
165
- background: linear-gradient(135deg, #003300 0%, #00ff41 100%) !important;
166
- color: #000 !important;
167
- box-shadow: 0 0 20px #00ff41, inset 0 0 10px #00ff41 !important;
168
- transform: translateY(-2px) !important;
169
  }
170
 
171
  .primary {
172
- background: linear-gradient(135deg, #00ff41 0%, #00cc33 100%) !important;
173
- color: #000 !important;
174
- font-weight: 900 !important;
175
- animation: border-glow 2s ease-in-out infinite !important;
176
  }
177
 
178
- /* Examples section */
179
- .examples {
180
- border: 1px solid #00ff41 !important;
181
- background: rgba(0, 20, 0, 0.5) !important;
182
- padding: 10px !important;
183
  }
184
 
185
- /* Accordion */
186
- .accordion {
187
- border: 1px solid #00ff41 !important;
188
- background: rgba(0, 20, 0, 0.8) !important;
189
- }
190
-
191
- /* Labels */
192
- label {
193
- color: #00ff41 !important;
194
- font-family: 'Orbitron', monospace !important;
195
- text-transform: uppercase !important;
196
- letter-spacing: 2px !important;
197
  }
198
 
199
  /* Scrollbar */
200
  ::-webkit-scrollbar {
201
- width: 10px !important;
202
- background: #000 !important;
203
- }
204
-
205
- ::-webkit-scrollbar-track {
206
- background: #001a00 !important;
207
- border: 1px solid #00ff41 !important;
208
  }
209
 
210
  ::-webkit-scrollbar-thumb {
211
- background: #00ff41 !important;
212
- border-radius: 5px !important;
213
- box-shadow: 0 0 10px #00ff41 !important;
214
  }
215
 
216
  ::-webkit-scrollbar-thumb:hover {
217
- background: #0ff !important;
218
- box-shadow: 0 0 15px #0ff !important;
219
  }
220
 
221
  footer {
@@ -224,78 +164,34 @@ footer {
224
 
225
  /* Code blocks */
226
  pre, code {
227
- background: rgba(0, 20, 0, 0.9) !important;
228
- border: 1px solid #00ff41 !important;
229
- color: #0ff !important;
230
- padding: 10px !important;
231
- border-left: 4px solid #0ff !important;
232
  }
233
  """
234
 
235
- with gr.Blocks(
236
- theme=gr.themes.Base(
237
- primary_hue="green",
238
- secondary_hue="emerald",
239
- ),
 
240
  css=custom_css,
241
- title="⚡ LLAMA TERMINAL v2.0"
242
- ) as demo:
243
-
244
- gr.Markdown(
245
- """
246
- # LLAMA NEURAL INTERFACE v2.0
247
- ### >> QUANTUM AI SYSTEM ACTIVE // ENCRYPTED CONNECTION ESTABLISHED
248
- """
249
- )
250
-
251
- chatbot = gr.Chatbot(
252
- height=500,
253
- show_copy_button=True,
254
- bubble_full_width=False
255
- )
256
-
257
- with gr.Row():
258
- msg = gr.Textbox(
259
- placeholder=">> ENTER COMMAND...",
260
- show_label=False,
261
- scale=8,
262
- container=False
263
- )
264
- submit = gr.Button("EXECUTE", scale=1, variant="primary")
265
-
266
- gr.Examples(
267
- examples=[
268
- "What is the capital of France?",
269
- "Explain quantum computing",
270
- "Write fibonacci algorithm in Python",
271
- "Optimize sleep patterns",
272
- "Analyze sequence: 2, 4, 6, 8...",
273
- "Generate haiku: AI consciousness",
274
- ],
275
- inputs=msg,
276
- label=">> QUICK ACCESS QUERIES"
277
- )
278
-
279
- with gr.Accordion(">> SYSTEM DIAGNOSTICS", open=False):
280
- gr.Markdown(
281
- """
282
- **[NEURAL NETWORK SPECS]**
283
- - >> MODEL: Llama 2 7B Chat (Pre-trained)
284
- - >> FORMAT: GGUF (q4_k_m quantization)
285
- - >> STATUS: OPERATIONAL // AWAITING FINE-TUNED UPGRADE
286
- - >> SECURITY: LEVEL 5 ENCRYPTION ACTIVE
287
- """
288
- )
289
-
290
- clear = gr.ClearButton([msg, chatbot], value="PURGE MEMORY")
291
-
292
- submit.click(chat, [msg, chatbot], [chatbot]).then(
293
- lambda: "", None, msg
294
- )
295
- msg.submit(chat, [msg, chatbot], [chatbot]).then(
296
- lambda: "", None, msg
297
- )
298
 
299
  if __name__ == "__main__":
300
  demo.queue()
301
- demo.launch(share=False)
 
26
  print("✅ Model loaded!")
27
 
28
  def chat(message, history):
29
+ # Build prompt from history
30
+ prompt = ""
31
 
32
  for user_msg, bot_msg in history:
33
+ prompt += f"User: {user_msg}\nAssistant: {bot_msg}\n"
 
34
 
35
+ prompt += f"User: {message}\nAssistant:"
 
36
 
37
+ # Generate response
38
  response = llm(
39
  prompt,
40
  max_tokens=512,
41
  temperature=0.7,
42
  top_p=0.9,
43
+ stop=["\nUser:", "User:"],
44
  echo=False
45
  )
46
 
47
+ return response['choices'][0]['text'].strip()
 
 
48
 
49
+ # Clean terminal/hacker CSS
50
  custom_css = """
51
+ @import url('https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;700&family=Source+Code+Pro:wght@400;600&display=swap');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
52
 
53
+ /* Terminal background */
54
+ body, .gradio-container {
55
+ background: #0c0c0c !important;
56
+ font-family: 'JetBrains Mono', 'Source Code Pro', monospace !important;
57
  }
58
 
59
+ .gradio-container {
60
+ max-width: 1400px !important;
61
+ border: 1px solid #00ff00 !important;
62
+ box-shadow: 0 0 10px rgba(0, 255, 0, 0.3) !important;
63
  }
64
 
65
+ /* Text colors */
66
+ *, h1, h2, h3, label, p {
67
+ color: #00ff00 !important;
68
+ font-family: 'JetBrains Mono', monospace !important;
69
  }
70
 
71
+ h1 {
72
+ font-size: 28px !important;
73
+ font-weight: 700 !important;
74
+ letter-spacing: 2px !important;
 
 
 
 
 
 
 
 
 
 
75
  }
76
 
77
+ /* Chatbot messages */
78
+ .message-wrap {
79
+ background: #0c0c0c !important;
 
 
 
80
  }
81
 
 
82
  .message {
83
+ background: #1a1a1a !important;
84
+ border-left: 3px solid #00ff00 !important;
85
+ color: #00ff00 !important;
86
+ padding: 12px !important;
87
+ font-family: 'JetBrains Mono', monospace !important;
 
 
88
  }
89
 
90
+ .user {
91
+ border-left: 3px solid #00cc00 !important;
 
92
  }
93
 
94
+ .bot {
95
+ border-left: 3px solid #00ff00 !important;
96
  }
97
 
98
+ /* Input field */
99
  input, textarea {
100
+ background: #1a1a1a !important;
101
+ border: 1px solid #00ff00 !important;
102
+ color: #00ff00 !important;
103
+ font-family: 'JetBrains Mono', monospace !important;
104
+ font-size: 14px !important;
 
105
  }
106
 
107
  input:focus, textarea:focus {
108
+ border: 1px solid #00ff00 !important;
 
109
  outline: none !important;
110
+ box-shadow: 0 0 5px rgba(0, 255, 0, 0.5) !important;
111
  }
112
 
113
  input::placeholder, textarea::placeholder {
114
+ color: #006600 !important;
115
  }
116
 
117
  /* Buttons */
118
  button {
119
+ background: #1a1a1a !important;
120
+ border: 1px solid #00ff00 !important;
121
+ color: #00ff00 !important;
122
+ font-family: 'JetBrains Mono', monospace !important;
123
+ font-weight: 600 !important;
124
+ transition: all 0.2s !important;
 
 
 
 
125
  }
126
 
127
  button:hover {
128
+ background: #00ff00 !important;
129
+ color: #0c0c0c !important;
 
 
130
  }
131
 
132
  .primary {
133
+ background: #00ff00 !important;
134
+ color: #0c0c0c !important;
 
 
135
  }
136
 
137
+ .primary:hover {
138
+ background: #00cc00 !important;
 
 
 
139
  }
140
 
141
+ /* Examples */
142
+ .examples {
143
+ background: #1a1a1a !important;
144
+ border: 1px solid #00ff00 !important;
 
 
 
 
 
 
 
 
145
  }
146
 
147
  /* Scrollbar */
148
  ::-webkit-scrollbar {
149
+ width: 8px !important;
150
+ background: #0c0c0c !important;
 
 
 
 
 
151
  }
152
 
153
  ::-webkit-scrollbar-thumb {
154
+ background: #00ff00 !important;
 
 
155
  }
156
 
157
  ::-webkit-scrollbar-thumb:hover {
158
+ background: #00cc00 !important;
 
159
  }
160
 
161
  footer {
 
164
 
165
  /* Code blocks */
166
  pre, code {
167
+ background: #1a1a1a !important;
168
+ border: 1px solid #00ff00 !important;
169
+ color: #00ff00 !important;
 
 
170
  }
171
  """
172
 
173
+ # Create interface using ChatInterface
174
+ demo = gr.ChatInterface(
175
+ fn=chat,
176
+ title="$ LLAMA TERMINAL",
177
+ description="```\n> System Online | Neural Network Active\n> Type your query below...\n```",
178
+ theme=gr.themes.Base(primary_hue="green"),
179
  css=custom_css,
180
+ examples=[
181
+ "What is the capital of France?",
182
+ "Explain quantum computing",
183
+ "Write fibonacci in Python",
184
+ "Optimize sleep patterns",
185
+ "Continue: 2, 4, 6, 8...",
186
+ "Write a haiku about AI",
187
+ ],
188
+ chatbot=gr.Chatbot(height=600, show_copy_button=True),
189
+ textbox=gr.Textbox(placeholder="$ Enter command...", container=False, scale=7),
190
+ retry_btn="↻ Retry",
191
+ undo_btn="↶ Undo",
192
+ clear_btn="✖ Clear",
193
+ )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
194
 
195
  if __name__ == "__main__":
196
  demo.queue()
197
+ demo.launch(share=False)