Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -35,7 +35,7 @@ if model_path:
|
|
| 35 |
# --- 3. Style / System Prompts ---
|
| 36 |
STYLE_SYSTEM_PROMPTS = {
|
| 37 |
"Default": "You are a helpful, polite assistant.",
|
| 38 |
-
"Short answer": "Answer as concisely as possible, usually in 1
|
| 39 |
"Detailed explanation": "Give clear, structured and detailed explanations.",
|
| 40 |
"Step-by-step reasoning": "Think step by step and explain your reasoning clearly.",
|
| 41 |
}
|
|
@@ -76,24 +76,7 @@ def chat_fn(message, history, max_new_tokens, style):
|
|
| 76 |
)
|
| 77 |
return output["choices"][0]["text"].strip()
|
| 78 |
|
| 79 |
-
# --- 4.
|
| 80 |
-
|
| 81 |
-
max_new_tokens_slider = gr.Slider(
|
| 82 |
-
minimum=16,
|
| 83 |
-
maximum=256,
|
| 84 |
-
value=64,
|
| 85 |
-
step=8,
|
| 86 |
-
label="Max Response Length"
|
| 87 |
-
)
|
| 88 |
-
|
| 89 |
-
style_radio = gr.Radio(
|
| 90 |
-
choices=["Default", "Short answer", "Detailed explanation", "Step-by-step reasoning"],
|
| 91 |
-
value="Detailed explanation",
|
| 92 |
-
label="Answer Style"
|
| 93 |
-
)
|
| 94 |
-
|
| 95 |
-
# --- 4.5. Background CSS ---
|
| 96 |
-
|
| 97 |
BACKGROUND_URL = "https://images.template.net/269645/Cute-Christmas-Background-edit-online-1.jpg"
|
| 98 |
|
| 99 |
custom_css = f"""
|
|
@@ -103,17 +86,38 @@ custom_css = f"""
|
|
| 103 |
background-size: cover;
|
| 104 |
background-position: center;
|
| 105 |
}}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 106 |
"""
|
| 107 |
|
| 108 |
-
# --- 5.
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 117 |
|
| 118 |
if __name__ == "__main__":
|
| 119 |
demo.launch()
|
|
|
|
| 35 |
# --- 3. Style / System Prompts ---
|
| 36 |
STYLE_SYSTEM_PROMPTS = {
|
| 37 |
"Default": "You are a helpful, polite assistant.",
|
| 38 |
+
"Short answer": "Answer as concisely as possible, usually in 1-3 sentences.",
|
| 39 |
"Detailed explanation": "Give clear, structured and detailed explanations.",
|
| 40 |
"Step-by-step reasoning": "Think step by step and explain your reasoning clearly.",
|
| 41 |
}
|
|
|
|
| 76 |
)
|
| 77 |
return output["choices"][0]["text"].strip()
|
| 78 |
|
| 79 |
+
# --- 4. Background CSS ---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 80 |
BACKGROUND_URL = "https://images.template.net/269645/Cute-Christmas-Background-edit-online-1.jpg"
|
| 81 |
|
| 82 |
custom_css = f"""
|
|
|
|
| 86 |
background-size: cover;
|
| 87 |
background-position: center;
|
| 88 |
}}
|
| 89 |
+
/* Optional: make main blocks a bit translucent so text is readable */
|
| 90 |
+
.gradio-container .block, .gradio-container .panel {{
|
| 91 |
+
background-color: rgba(255, 255, 255, 0.85);
|
| 92 |
+
}}
|
| 93 |
"""
|
| 94 |
|
| 95 |
+
# --- 5. Build UI inside Blocks (so we can use css) ---
|
| 96 |
+
with gr.Blocks(title="Lab 2 - Fine-tuned GGUF model", css=custom_css) as demo:
|
| 97 |
+
gr.Markdown(
|
| 98 |
+
"# Lab 2 - Fine-tuned GGUF model\n"
|
| 99 |
+
"Chat with the fine-tuned Llama model. Use the controls below to change the response style."
|
| 100 |
+
)
|
| 101 |
+
|
| 102 |
+
with gr.Accordion("Controls", open=True):
|
| 103 |
+
max_new_tokens_slider = gr.Slider(
|
| 104 |
+
minimum=16,
|
| 105 |
+
maximum=256,
|
| 106 |
+
value=64,
|
| 107 |
+
step=8,
|
| 108 |
+
label="Max Response Length",
|
| 109 |
+
)
|
| 110 |
+
|
| 111 |
+
style_radio = gr.Radio(
|
| 112 |
+
choices=["Default", "Short answer", "Detailed explanation", "Step-by-step reasoning"],
|
| 113 |
+
value="Detailed explanation",
|
| 114 |
+
label="Answer Style",
|
| 115 |
+
)
|
| 116 |
+
|
| 117 |
+
gr.ChatInterface(
|
| 118 |
+
fn=chat_fn,
|
| 119 |
+
additional_inputs=[max_new_tokens_slider, style_radio],
|
| 120 |
+
)
|
| 121 |
|
| 122 |
if __name__ == "__main__":
|
| 123 |
demo.launch()
|