Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -22,6 +22,7 @@ MODEL_SUBFOLDER = os.getenv('MODEL_SUBFOLDER', '')
|
|
22 |
MODEL_IDENTITY = os.getenv('MODEL_IDENTITY', '')
|
23 |
DEFAULT_SYSTEM_PROMPT = os.getenv('SYSTEM_MESSAGE', MODEL_IDENTITY or 'You are a helpful assistant. Reasoning: medium')
|
24 |
DEFAULT_DEVELOPER_PROMPT = os.getenv('DEVELOPER_MESSAGE', '')
|
|
|
25 |
|
26 |
# If the LORA_MODEL_ID is the same as BASE_MODEL_ID, this is a merged model, not LoRA
|
27 |
USE_LORA = LORA_MODEL_ID != BASE_MODEL_ID and not LORA_MODEL_ID.startswith(BASE_MODEL_ID)
|
@@ -135,7 +136,7 @@ def format_analysis_response(text):
|
|
135 |
return cleaned
|
136 |
|
137 |
@spaces.GPU(duration=60)
|
138 |
-
def generate_response(input_data, chat_history, max_new_tokens, model_identity, system_prompt, developer_prompt, temperature, top_p, top_k, repetition_penalty):
|
139 |
if not input_data.strip():
|
140 |
yield "Please enter a prompt."
|
141 |
return
|
@@ -146,10 +147,15 @@ def generate_response(input_data, chat_history, max_new_tokens, model_identity,
|
|
146 |
|
147 |
new_message = {"role": "user", "content": input_data}
|
148 |
# Combine model identity with system prompt for a single system message
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
|
|
|
|
|
|
|
|
|
|
153 |
system_message = ([{"role": "system", "content": combined_system}] if combined_system else [])
|
154 |
developer_message = [{"role": "developer", "content": developer_prompt}] if developer_prompt else []
|
155 |
processed_history = format_conversation_history(chat_history)
|
@@ -252,6 +258,12 @@ demo = gr.ChatInterface(
|
|
252 |
lines=4,
|
253 |
placeholder="Optional developer instructions"
|
254 |
),
|
|
|
|
|
|
|
|
|
|
|
|
|
255 |
gr.Slider(label="Temperature", minimum=0.1, maximum=2.0, step=0.1, value=0.7),
|
256 |
gr.Slider(label="Top-p", minimum=0.05, maximum=1.0, step=0.05, value=0.9),
|
257 |
gr.Slider(label="Top-k", minimum=1, maximum=100, step=1, value=50),
|
|
|
22 |
MODEL_IDENTITY = os.getenv('MODEL_IDENTITY', '')
|
23 |
DEFAULT_SYSTEM_PROMPT = os.getenv('SYSTEM_MESSAGE', MODEL_IDENTITY or 'You are a helpful assistant. Reasoning: medium')
|
24 |
DEFAULT_DEVELOPER_PROMPT = os.getenv('DEVELOPER_MESSAGE', '')
|
25 |
+
DEFAULT_REASONING_EFFORT = os.getenv('REASONING_EFFORT', 'medium')
|
26 |
|
27 |
# If the LORA_MODEL_ID is the same as BASE_MODEL_ID, this is a merged model, not LoRA
|
28 |
USE_LORA = LORA_MODEL_ID != BASE_MODEL_ID and not LORA_MODEL_ID.startswith(BASE_MODEL_ID)
|
|
|
136 |
return cleaned
|
137 |
|
138 |
@spaces.GPU(duration=60)
|
139 |
+
def generate_response(input_data, chat_history, max_new_tokens, model_identity, system_prompt, developer_prompt, reasoning_effort, temperature, top_p, top_k, repetition_penalty):
|
140 |
if not input_data.strip():
|
141 |
yield "Please enter a prompt."
|
142 |
return
|
|
|
147 |
|
148 |
new_message = {"role": "user", "content": input_data}
|
149 |
# Combine model identity with system prompt for a single system message
|
150 |
+
combined_parts = []
|
151 |
+
if model_identity and model_identity.strip():
|
152 |
+
combined_parts.append(model_identity.strip())
|
153 |
+
if system_prompt and system_prompt.strip():
|
154 |
+
combined_parts.append(system_prompt.strip())
|
155 |
+
if reasoning_effort and isinstance(reasoning_effort, str) and reasoning_effort.strip():
|
156 |
+
# Append explicit reasoning directive
|
157 |
+
combined_parts.append(f"Reasoning: {reasoning_effort.strip()}")
|
158 |
+
combined_system = "\n\n".join(combined_parts).strip()
|
159 |
system_message = ([{"role": "system", "content": combined_system}] if combined_system else [])
|
160 |
developer_message = [{"role": "developer", "content": developer_prompt}] if developer_prompt else []
|
161 |
processed_history = format_conversation_history(chat_history)
|
|
|
258 |
lines=4,
|
259 |
placeholder="Optional developer instructions"
|
260 |
),
|
261 |
+
gr.Dropdown(
|
262 |
+
label="Reasoning Effort",
|
263 |
+
choices=["low", "medium", "high"],
|
264 |
+
value=DEFAULT_REASONING_EFFORT,
|
265 |
+
interactive=True,
|
266 |
+
),
|
267 |
gr.Slider(label="Temperature", minimum=0.1, maximum=2.0, step=0.1, value=0.7),
|
268 |
gr.Slider(label="Top-p", minimum=0.05, maximum=1.0, step=0.05, value=0.9),
|
269 |
gr.Slider(label="Top-k", minimum=1, maximum=100, step=1, value=50),
|