Spaces:
Sleeping
Sleeping
Update nikapp.py
Browse files
nikapp.py
CHANGED
|
@@ -57,7 +57,7 @@ def chat_fn(message, history, max_new_tokens):
|
|
| 57 |
prompt = build_prompt(message, history)
|
| 58 |
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
|
| 59 |
|
| 60 |
-
# Default values
|
| 61 |
temperature = 0.7
|
| 62 |
top_p = 0.9
|
| 63 |
repetition_penalty = 1.1
|
|
@@ -81,23 +81,67 @@ def chat_fn(message, history, max_new_tokens):
|
|
| 81 |
|
| 82 |
return generated
|
| 83 |
|
| 84 |
-
# ---
|
|
|
|
|
|
|
| 85 |
nature_theme = gr.themes.Soft(
|
| 86 |
primary_hue="green",
|
| 87 |
secondary_hue="emerald",
|
| 88 |
neutral_hue="stone",
|
| 89 |
).set(
|
| 90 |
-
|
| 91 |
-
|
|
|
|
|
|
|
|
|
|
| 92 |
button_primary_background_fill="#2E7D32",
|
| 93 |
-
|
| 94 |
)
|
| 95 |
|
|
|
|
| 96 |
custom_css = """
|
|
|
|
| 97 |
.gradio-container {
|
| 98 |
background: url('https://images.unsplash.com/photo-1441974231531-c6227db76b6e?q=80&w=2560&auto=format&fit=crop') no-repeat center center fixed;
|
| 99 |
background-size: cover;
|
| 100 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 101 |
footer {visibility: hidden}
|
| 102 |
"""
|
| 103 |
|
|
@@ -105,7 +149,7 @@ max_new_tokens_slider = gr.Slider(
|
|
| 105 |
minimum=16, maximum=512, value=128, step=8, label="Response Length (Tokens)",
|
| 106 |
)
|
| 107 |
|
| 108 |
-
# Instantiate ChatInterface
|
| 109 |
demo = gr.ChatInterface(
|
| 110 |
fn=chat_fn,
|
| 111 |
title="🌿 NatureChat Lab 2",
|
|
@@ -114,7 +158,7 @@ demo = gr.ChatInterface(
|
|
| 114 |
additional_inputs_accordion="Settings"
|
| 115 |
)
|
| 116 |
|
| 117 |
-
# Apply
|
| 118 |
demo.theme = nature_theme
|
| 119 |
demo.css = custom_css
|
| 120 |
|
|
|
|
| 57 |
prompt = build_prompt(message, history)
|
| 58 |
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
|
| 59 |
|
| 60 |
+
# Default values
|
| 61 |
temperature = 0.7
|
| 62 |
top_p = 0.9
|
| 63 |
repetition_penalty = 1.1
|
|
|
|
| 81 |
|
| 82 |
return generated
|
| 83 |
|
| 84 |
+
# --- Visual Customization ---
|
| 85 |
+
|
| 86 |
+
# 1. THEME: Set the base colors to forest greens
|
| 87 |
nature_theme = gr.themes.Soft(
|
| 88 |
primary_hue="green",
|
| 89 |
secondary_hue="emerald",
|
| 90 |
neutral_hue="stone",
|
| 91 |
).set(
|
| 92 |
+
# Make the default backgrounds transparent or dark to blend with image
|
| 93 |
+
body_background_fill="transparent",
|
| 94 |
+
block_background_fill="rgba(20, 30, 20, 0.8)", # Dark semi-transparent green
|
| 95 |
+
border_color_primary="#4CAF50", # Bright Green border
|
| 96 |
+
input_background_fill="rgba(0, 0, 0, 0.5)",
|
| 97 |
button_primary_background_fill="#2E7D32",
|
| 98 |
+
text_color_subdued="#A5D6A7", # Light green text for labels
|
| 99 |
)
|
| 100 |
|
| 101 |
+
# 2. CSS: Force the background image and specific "Green Border" look
|
| 102 |
custom_css = """
|
| 103 |
+
/* The Main Forest Background */
|
| 104 |
.gradio-container {
|
| 105 |
background: url('https://images.unsplash.com/photo-1441974231531-c6227db76b6e?q=80&w=2560&auto=format&fit=crop') no-repeat center center fixed;
|
| 106 |
background-size: cover;
|
| 107 |
}
|
| 108 |
+
|
| 109 |
+
/* Make the main App container transparent so background shows */
|
| 110 |
+
.gradio-container > .main {
|
| 111 |
+
background: transparent !important;
|
| 112 |
+
}
|
| 113 |
+
|
| 114 |
+
/* Chatbot Window Styling - The "Glassy" Look */
|
| 115 |
+
.bubble-wrap {
|
| 116 |
+
background: rgba(0, 0, 0, 0.6) !important;
|
| 117 |
+
border: 1px solid #4CAF50 !important;
|
| 118 |
+
border-radius: 10px !important;
|
| 119 |
+
}
|
| 120 |
+
|
| 121 |
+
/* User and Bot message bubbles */
|
| 122 |
+
.user-message {
|
| 123 |
+
background-color: #2E7D32 !important; /* Forest Green for user */
|
| 124 |
+
border: 1px solid #66BB6A !important;
|
| 125 |
+
}
|
| 126 |
+
.bot-message {
|
| 127 |
+
background-color: rgba(40, 40, 40, 0.9) !important; /* Dark Grey for bot */
|
| 128 |
+
border: 1px solid #4CAF50 !important;
|
| 129 |
+
}
|
| 130 |
+
|
| 131 |
+
/* Input Area and Settings - Green Borders */
|
| 132 |
+
.group, .form {
|
| 133 |
+
background: rgba(10, 20, 10, 0.85) !important; /* Dark semi-transparent */
|
| 134 |
+
border: 2px solid #4CAF50 !important; /* The prominent green border */
|
| 135 |
+
border-radius: 8px;
|
| 136 |
+
padding: 10px;
|
| 137 |
+
}
|
| 138 |
+
|
| 139 |
+
/* Text colors */
|
| 140 |
+
label, span, p {
|
| 141 |
+
color: #E8F5E9 !important; /* Very light green/white text */
|
| 142 |
+
}
|
| 143 |
+
|
| 144 |
+
/* Hide Footer */
|
| 145 |
footer {visibility: hidden}
|
| 146 |
"""
|
| 147 |
|
|
|
|
| 149 |
minimum=16, maximum=512, value=128, step=8, label="Response Length (Tokens)",
|
| 150 |
)
|
| 151 |
|
| 152 |
+
# Instantiate ChatInterface
|
| 153 |
demo = gr.ChatInterface(
|
| 154 |
fn=chat_fn,
|
| 155 |
title="🌿 NatureChat Lab 2",
|
|
|
|
| 158 |
additional_inputs_accordion="Settings"
|
| 159 |
)
|
| 160 |
|
| 161 |
+
# Apply the Theme and CSS manually (Compatible with older Gradio versions)
|
| 162 |
demo.theme = nature_theme
|
| 163 |
demo.css = custom_css
|
| 164 |
|