ndahlbom commited on
Commit
3ef2b47
·
verified ·
1 Parent(s): bdc4337

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -42
app.py CHANGED
@@ -16,8 +16,9 @@ try:
16
  repo_id=MODEL_REPO,
17
  filename=GGUF_FILENAME,
18
  )
19
- except Exception:
20
- model_path = "" # Handle offline/error gracefully
 
21
 
22
  llm = None
23
  if model_path:
@@ -46,7 +47,6 @@ def _extract_text(content):
46
  def chat_fn(message, history, max_new_tokens, style):
47
  if not llm: return "Error: Model not loaded."
48
 
49
- # Logic
50
  system_prompt = STYLE_SYSTEM_PROMPTS.get(style, STYLE_SYSTEM_PROMPTS["Default"])
51
  prompt = f"System: {system_prompt}\nConversation:\n"
52
  for msg in history or []:
@@ -66,59 +66,52 @@ def chat_fn(message, history, max_new_tokens, style):
66
  )
67
  return output["choices"][0]["text"].strip()
68
 
69
- # --- 4. THEME CSS (The Magic Part) ---
 
70
  christmas_css = """
71
- /* Import a festive/elegant font */
72
  @import url('https://fonts.googleapis.com/css2?family=Cinzel:wght@400;700&family=Lato:wght@400;700&display=swap');
73
 
74
  body {
75
- /* Main Background: Snowy Forest */
76
- background: url('https://images.unsplash.com/photo-1543169176-78e7c10b27b6?q=80&w=2560&auto=format&fit=crop') no-repeat center center fixed;
77
- background-size: cover;
78
  color: #f0f0f0;
79
  font-family: "Lato", sans-serif;
80
  }
81
 
82
- /* Headings */
83
  h1, h2, h3 {
84
  font-family: "Cinzel", serif;
85
- color: #FFD700 !important; /* Gold text */
86
  text-shadow: 0px 2px 4px rgba(0,0,0,0.8);
87
  text-transform: uppercase;
88
  }
89
 
90
- /* 1. HERO SECTION (The Header) */
91
  .hero {
92
  position: relative;
93
  margin: 1rem auto;
94
  max-width: 900px;
95
  padding: 2rem;
96
  border-radius: 20px;
97
- /* Glassy Red/Dark background */
98
- background: linear-gradient(135deg, rgba(40, 0, 0, 0.85), rgba(10, 20, 30, 0.9));
99
  border: 2px solid #D4AF37; /* Gold Border */
100
  box-shadow: 0 0 30px rgba(0, 0, 0, 0.8), 0 0 10px rgba(212, 175, 55, 0.3);
101
  overflow: hidden;
102
- }
103
-
104
- .hero-inner {
105
  display: flex;
106
- gap: 1.5rem;
107
  align-items: center;
108
- position: relative;
109
- z-index: 2;
110
  }
111
 
112
- /* The Round Avatar Image */
113
  .hero-image {
114
- flex-shrink: 0;
115
  width: 100px;
116
  height: 100px;
117
  border-radius: 50%;
118
- border: 3px solid #D4AF37; /* Gold */
119
  overflow: hidden;
120
- box-shadow: 0 0 20px rgba(0,0,0,0.8);
121
  }
 
122
  .hero-image img {
123
  width: 100%;
124
  height: 100%;
@@ -130,11 +123,11 @@ h1, h2, h3 {
130
  font-size: 1.8rem;
131
  letter-spacing: 0.1em;
132
  }
 
133
  .hero-text p {
134
  margin-top: 0.5rem;
135
  font-size: 1rem;
136
  color: #E0E0E0;
137
- line-height: 1.4;
138
  }
139
 
140
  /* 2. GRADIO CONTAINER TRANSPARENCY */
@@ -142,24 +135,24 @@ h1, h2, h3 {
142
  background: transparent !important;
143
  }
144
 
145
- /* 3. CHAT INTERFACE & INPUTS */
146
  .group, .form, .bubble-wrap {
147
- background: rgba(15, 23, 42, 0.85) !important; /* Dark Glass */
148
  border: 1px solid rgba(255, 255, 255, 0.3) !important;
149
  border-radius: 15px !important;
150
  backdrop-filter: blur(5px);
151
  }
152
 
153
- /* Chat Messages */
154
  .user-message {
155
- background: linear-gradient(135deg, #8E0E00, #1F1C18) !important; /* Deep Red */
156
- border-left: 4px solid #D4AF37 !important; /* Gold accent */
157
  color: white !important;
158
  }
159
 
160
  .bot-message {
161
- background: linear-gradient(135deg, #134E5E, #1F1C18) !important; /* Deep Green */
162
- border-left: 4px solid #71B280 !important; /* Light Green accent */
163
  color: #E0E0E0 !important;
164
  }
165
 
@@ -168,51 +161,52 @@ textarea, input {
168
  background-color: rgba(0, 0, 0, 0.6) !important;
169
  border: 1px solid #D4AF37 !important;
170
  color: white !important;
171
- border-radius: 20px !important;
172
  }
173
 
174
  /* Buttons */
175
- button.primary {
176
  background: linear-gradient(to right, #D4AF37, #C5A028) !important;
177
  color: black !important;
178
  font-weight: bold !important;
179
  border: none !important;
180
  }
 
181
  """
182
 
183
  # --- 5. BUILD THE UI ---
184
- with gr.Blocks(css=christmas_css, title="Christmas Lab 2") as demo:
 
185
 
186
- # HTML Header (The "Hero")
187
  gr.HTML(
188
  """
189
  <div class="hero">
190
- <div class="hero-inner">
191
  <div class="hero-image">
192
  <img src="https://images.unsplash.com/photo-1482517967863-00e15c9b4499?q=80&w=400&auto=format&fit=crop" alt="Christmas AI">
193
  </div>
194
  <div class="hero-text">
195
- <h1>Holiday AI Assistant</h1>
196
  <p>
197
- Welcome to the Winter Workshop. I am powered by fine-tuned Llama models
198
- and hot cocoa. Ask me anything, and stay frosty!
199
  </p>
200
  </div>
201
- </div>
202
  </div>
203
  """
204
  )
205
 
206
- # The Chat Interface
207
- # Note: We pass the sliders here as 'additional_inputs' just like before
208
  max_new_tokens_slider = gr.Slider(minimum=16, maximum=256, value=64, step=8, label="Max Response Length")
209
  style_radio = gr.Radio(["Default", "Short answer", "Detailed explanation"], value="Detailed explanation", label="Style")
210
 
 
211
  chat = gr.ChatInterface(
212
  fn=chat_fn,
213
  additional_inputs=[max_new_tokens_slider, style_radio],
214
  additional_inputs_accordion="Workshop Settings",
215
  )
216
 
 
 
 
217
  if __name__ == "__main__":
218
  demo.launch(allowed_paths=["."])
 
16
  repo_id=MODEL_REPO,
17
  filename=GGUF_FILENAME,
18
  )
19
+ except Exception as e:
20
+ print(f"Error: {e}")
21
+ model_path = ""
22
 
23
  llm = None
24
  if model_path:
 
47
  def chat_fn(message, history, max_new_tokens, style):
48
  if not llm: return "Error: Model not loaded."
49
 
 
50
  system_prompt = STYLE_SYSTEM_PROMPTS.get(style, STYLE_SYSTEM_PROMPTS["Default"])
51
  prompt = f"System: {system_prompt}\nConversation:\n"
52
  for msg in history or []:
 
66
  )
67
  return output["choices"][0]["text"].strip()
68
 
69
+ # --- 4. THEME CSS ---
70
+ # Note: We use a reliable Unsplash URL for the background to avoid file path errors
71
  christmas_css = """
72
+ /* Import a festive font */
73
  @import url('https://fonts.googleapis.com/css2?family=Cinzel:wght@400;700&family=Lato:wght@400;700&display=swap');
74
 
75
  body {
76
+ background: url('https://images.unsplash.com/photo-1543169176-78e7c10b27b6?q=80&w=2560&auto=format&fit=crop') no-repeat center center fixed !important;
77
+ background-size: cover !important;
 
78
  color: #f0f0f0;
79
  font-family: "Lato", sans-serif;
80
  }
81
 
 
82
  h1, h2, h3 {
83
  font-family: "Cinzel", serif;
84
+ color: #FFD700 !important; /* Gold */
85
  text-shadow: 0px 2px 4px rgba(0,0,0,0.8);
86
  text-transform: uppercase;
87
  }
88
 
89
+ /* 1. HERO HEADER STYLES */
90
  .hero {
91
  position: relative;
92
  margin: 1rem auto;
93
  max-width: 900px;
94
  padding: 2rem;
95
  border-radius: 20px;
96
+ /* Dark Holiday Red/Black Gradient */
97
+ background: linear-gradient(135deg, rgba(60, 10, 10, 0.9), rgba(10, 20, 30, 0.95));
98
  border: 2px solid #D4AF37; /* Gold Border */
99
  box-shadow: 0 0 30px rgba(0, 0, 0, 0.8), 0 0 10px rgba(212, 175, 55, 0.3);
100
  overflow: hidden;
 
 
 
101
  display: flex;
 
102
  align-items: center;
103
+ gap: 20px;
 
104
  }
105
 
 
106
  .hero-image {
 
107
  width: 100px;
108
  height: 100px;
109
  border-radius: 50%;
110
+ border: 3px solid #D4AF37;
111
  overflow: hidden;
112
+ flex-shrink: 0;
113
  }
114
+
115
  .hero-image img {
116
  width: 100%;
117
  height: 100%;
 
123
  font-size: 1.8rem;
124
  letter-spacing: 0.1em;
125
  }
126
+
127
  .hero-text p {
128
  margin-top: 0.5rem;
129
  font-size: 1rem;
130
  color: #E0E0E0;
 
131
  }
132
 
133
  /* 2. GRADIO CONTAINER TRANSPARENCY */
 
135
  background: transparent !important;
136
  }
137
 
138
+ /* 3. COMPONENT STYLING */
139
  .group, .form, .bubble-wrap {
140
+ background: rgba(15, 23, 42, 0.85) !important;
141
  border: 1px solid rgba(255, 255, 255, 0.3) !important;
142
  border-radius: 15px !important;
143
  backdrop-filter: blur(5px);
144
  }
145
 
146
+ /* Messages */
147
  .user-message {
148
+ background: linear-gradient(135deg, #8E0E00, #3E0000) !important; /* Holiday Red */
149
+ border-left: 4px solid #D4AF37 !important;
150
  color: white !important;
151
  }
152
 
153
  .bot-message {
154
+ background: linear-gradient(135deg, #0f2e18, #05140a) !important; /* Pine Green */
155
+ border-left: 4px solid #71B280 !important;
156
  color: #E0E0E0 !important;
157
  }
158
 
 
161
  background-color: rgba(0, 0, 0, 0.6) !important;
162
  border: 1px solid #D4AF37 !important;
163
  color: white !important;
 
164
  }
165
 
166
  /* Buttons */
167
+ button {
168
  background: linear-gradient(to right, #D4AF37, #C5A028) !important;
169
  color: black !important;
170
  font-weight: bold !important;
171
  border: none !important;
172
  }
173
+ footer {visibility: hidden}
174
  """
175
 
176
  # --- 5. BUILD THE UI ---
177
+ # FIX: Removed 'css' from constructor to prevent TypeError
178
+ with gr.Blocks(title="Christmas Lab 2") as demo:
179
 
180
+ # HTML Header
181
  gr.HTML(
182
  """
183
  <div class="hero">
 
184
  <div class="hero-image">
185
  <img src="https://images.unsplash.com/photo-1482517967863-00e15c9b4499?q=80&w=400&auto=format&fit=crop" alt="Christmas AI">
186
  </div>
187
  <div class="hero-text">
188
+ <h1>Holiday AI Workshop</h1>
189
  <p>
190
+ Welcome to the Winter Lab. I am powered by fine-tuned Llama models
191
+ and hot cocoa. Ask me anything!
192
  </p>
193
  </div>
 
194
  </div>
195
  """
196
  )
197
 
 
 
198
  max_new_tokens_slider = gr.Slider(minimum=16, maximum=256, value=64, step=8, label="Max Response Length")
199
  style_radio = gr.Radio(["Default", "Short answer", "Detailed explanation"], value="Detailed explanation", label="Style")
200
 
201
+ # Chat Interface
202
  chat = gr.ChatInterface(
203
  fn=chat_fn,
204
  additional_inputs=[max_new_tokens_slider, style_radio],
205
  additional_inputs_accordion="Workshop Settings",
206
  )
207
 
208
+ # FIX: Assign CSS manually after creation
209
+ demo.css = christmas_css
210
+
211
  if __name__ == "__main__":
212
  demo.launch(allowed_paths=["."])