ndahlbom commited on
Commit
fd3f736
·
verified ·
1 Parent(s): 0e5f57b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -16
app.py CHANGED
@@ -3,7 +3,6 @@ import subprocess
3
  from huggingface_hub import hf_hub_download
4
 
5
  # --- 1. Setup & Install ---
6
- # Install llama-cpp-python in runtime (prevents build errors in Spaces)
7
  subprocess.run("pip install -q 'llama_cpp_python==0.3.15'", shell=True, check=False)
8
 
9
  from llama_cpp import Llama
@@ -60,7 +59,7 @@ def build_prompt(message, history, style):
60
  return "".join(prompt_parts)
61
 
62
  def chat_fn(message, history, max_new_tokens, style):
63
- # Hardcoded values for the hidden sliders
64
  temperature = 0.7
65
  top_p = 0.9
66
  repetition_penalty = 1.1
@@ -79,17 +78,16 @@ def chat_fn(message, history, max_new_tokens, style):
79
 
80
  # --- 4. Winter/Christmas Theme Configuration ---
81
 
82
- # We create a base theme, but most work is done in CSS
83
  winter_theme = gr.themes.Soft(
84
- primary_hue="blue", # Ice blue accents
85
  neutral_hue="slate",
86
  ).set(
87
  body_background_fill="transparent",
88
- block_background_fill="rgba(10, 20, 40, 0.7)", # Dark Blue Glass
89
- border_color_primary="#FFFFFF", # Explicit White Border
90
- button_primary_background_fill="#FFFFFF", # White buttons
91
  button_primary_text_color="#000000",
92
- text_color_subdued="#E0E0E0",
93
  )
94
 
95
  # Custom CSS for the "Perfect" Look
@@ -110,7 +108,7 @@ custom_css = """
110
  background: rgba(15, 23, 42, 0.75) !important; /* Dark Blue/Grey Glass */
111
  border: 2px solid #FFFFFF !important; /* THE WHITE BORDER */
112
  border-radius: 12px !important;
113
- backdrop-filter: blur(4px); /* Slight blur behind the glass */
114
  box-shadow: 0 4px 15px rgba(0,0,0,0.5);
115
  }
116
 
@@ -122,7 +120,7 @@ custom_css = """
122
  }
123
 
124
  .bot-message {
125
- background-color: rgba(0, 0, 0, 0.6) !important; /* Darker for contrast */
126
  border: 1px solid #A0A0A0 !important;
127
  color: #E0E0E0 !important;
128
  }
@@ -133,16 +131,16 @@ textarea, input {
133
  border: 1px solid #FFFFFF !important;
134
  color: white !important;
135
  }
136
- label, span, p {
 
137
  color: #FFFFFF !important;
138
- text-shadow: 1px 1px 2px black; /* Makes text readable on snow */
139
  }
140
 
141
  /* Hide Footer */
142
  footer {visibility: hidden}
143
  """
144
 
145
- # Only Max Tokens + Style
146
  max_new_tokens_slider = gr.Slider(
147
  minimum=16, maximum=256, value=64, step=8, label="Max Response Length",
148
  )
@@ -152,16 +150,14 @@ style_radio = gr.Radio(
152
  label="Answer style",
153
  )
154
 
155
- # Init App
156
  demo = gr.ChatInterface(
157
  fn=chat_fn,
158
  title="❄️ WinterChat Lab 2 ❄️",
159
- description="Stay frosty. Chat with the fine-tuned model",
160
  additional_inputs=[max_new_tokens_slider, style_radio],
161
  additional_inputs_accordion="Settings",
162
  )
163
 
164
- # Apply Visuals manually
165
  demo.theme = winter_theme
166
  demo.css = custom_css
167
 
 
3
  from huggingface_hub import hf_hub_download
4
 
5
  # --- 1. Setup & Install ---
 
6
  subprocess.run("pip install -q 'llama_cpp_python==0.3.15'", shell=True, check=False)
7
 
8
  from llama_cpp import Llama
 
59
  return "".join(prompt_parts)
60
 
61
  def chat_fn(message, history, max_new_tokens, style):
62
+ # Hardcoded values
63
  temperature = 0.7
64
  top_p = 0.9
65
  repetition_penalty = 1.1
 
78
 
79
  # --- 4. Winter/Christmas Theme Configuration ---
80
 
81
+ # We remove the specific 'text_color_subdued' argument to fix the crash
82
  winter_theme = gr.themes.Soft(
83
+ primary_hue="blue",
84
  neutral_hue="slate",
85
  ).set(
86
  body_background_fill="transparent",
87
+ block_background_fill="rgba(10, 20, 40, 0.7)",
88
+ border_color_primary="#FFFFFF",
89
+ button_primary_background_fill="#FFFFFF",
90
  button_primary_text_color="#000000",
 
91
  )
92
 
93
  # Custom CSS for the "Perfect" Look
 
108
  background: rgba(15, 23, 42, 0.75) !important; /* Dark Blue/Grey Glass */
109
  border: 2px solid #FFFFFF !important; /* THE WHITE BORDER */
110
  border-radius: 12px !important;
111
+ backdrop-filter: blur(4px);
112
  box-shadow: 0 4px 15px rgba(0,0,0,0.5);
113
  }
114
 
 
120
  }
121
 
122
  .bot-message {
123
+ background-color: rgba(0, 0, 0, 0.6) !important;
124
  border: 1px solid #A0A0A0 !important;
125
  color: #E0E0E0 !important;
126
  }
 
131
  border: 1px solid #FFFFFF !important;
132
  color: white !important;
133
  }
134
+ /* This CSS handles the text color we removed from the Python code */
135
+ label, span, p, .prose {
136
  color: #FFFFFF !important;
137
+ text-shadow: 1px 1px 2px black;
138
  }
139
 
140
  /* Hide Footer */
141
  footer {visibility: hidden}
142
  """
143
 
 
144
  max_new_tokens_slider = gr.Slider(
145
  minimum=16, maximum=256, value=64, step=8, label="Max Response Length",
146
  )
 
150
  label="Answer style",
151
  )
152
 
 
153
  demo = gr.ChatInterface(
154
  fn=chat_fn,
155
  title="❄️ WinterChat Lab 2 ❄️",
156
+ description="Stay frosty. Chat with the fine-tuned model.",
157
  additional_inputs=[max_new_tokens_slider, style_radio],
158
  additional_inputs_accordion="Settings",
159
  )
160
 
 
161
  demo.theme = winter_theme
162
  demo.css = custom_css
163