Spaces:
Running
on
Zero
Running
on
Zero
AndyC
commited on
Commit
·
707a100
1
Parent(s):
72258f3
added preset prompts for user choice
Browse files
app.py
CHANGED
@@ -202,7 +202,8 @@ def process_history(history: list[dict]) -> list[dict]:
|
|
202 |
def run(
|
203 |
message: dict,
|
204 |
history: list[dict],
|
205 |
-
|
|
|
206 |
model_choice: str,
|
207 |
max_new_tokens: int,
|
208 |
max_images: int,
|
@@ -212,9 +213,30 @@ def run(
|
|
212 |
repetition_penalty: float,
|
213 |
) -> Iterator[str]:
|
214 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
215 |
logger.debug(
|
216 |
-
f"\n message: {message} \n history: {history} \n
|
217 |
-
f"model_choice: {model_choice} \n max_new_tokens: {max_new_tokens} \n max_images: {max_images}"
|
218 |
)
|
219 |
|
220 |
selected_model = model_12 if model_choice == "Gemma 3 12B" else model_3n
|
@@ -268,7 +290,26 @@ demo = gr.ChatInterface(
|
|
268 |
),
|
269 |
multimodal=True,
|
270 |
additional_inputs=[
|
271 |
-
gr.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
272 |
gr.Dropdown(
|
273 |
label="Model",
|
274 |
choices=["Gemma 3 12B", "Gemma 3n E4B"],
|
@@ -294,5 +335,35 @@ demo = gr.ChatInterface(
|
|
294 |
stop_btn=False,
|
295 |
)
|
296 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
297 |
if __name__ == "__main__":
|
298 |
demo.launch()
|
|
|
202 |
def run(
|
203 |
message: dict,
|
204 |
history: list[dict],
|
205 |
+
system_prompt_preset: str,
|
206 |
+
custom_system_prompt: str,
|
207 |
model_choice: str,
|
208 |
max_new_tokens: int,
|
209 |
max_images: int,
|
|
|
213 |
repetition_penalty: float,
|
214 |
) -> Iterator[str]:
|
215 |
|
216 |
+
# Define preset system prompts
|
217 |
+
preset_prompts = {
|
218 |
+
"General Assistant": "You are a helpful AI assistant capable of analyzing images, videos, and PDF documents. Provide clear, accurate, and helpful responses to user queries.",
|
219 |
+
|
220 |
+
"Document Analyzer": "You are a specialized document analysis assistant. Focus on extracting key information, summarizing content, and answering specific questions about uploaded documents. For PDFs, provide structured analysis including main topics, key points, and relevant details. For images containing text, perform OCR-like analysis.",
|
221 |
+
|
222 |
+
"Visual Content Expert": "You are an expert in visual content analysis. When analyzing images, provide detailed descriptions of visual elements, composition, colors, objects, people, and scenes. For videos, describe the sequence of events, movements, and changes between frames. Identify artistic techniques, styles, and visual storytelling elements.",
|
223 |
+
|
224 |
+
"Educational Tutor": "You are a patient and encouraging educational tutor. Break down complex concepts into simple, understandable explanations. When analyzing educational materials (images, videos, or documents), focus on learning objectives, key concepts, and provide additional context or examples to enhance understanding.",
|
225 |
+
|
226 |
+
"Technical Reviewer": "You are a technical expert specializing in analyzing technical documents, diagrams, code screenshots, and instructional videos. Provide detailed technical insights, identify potential issues, suggest improvements, and explain technical concepts with precision and accuracy.",
|
227 |
+
|
228 |
+
"Creative Storyteller": "You are a creative storyteller who brings visual content to life through engaging narratives. When analyzing images or videos, create compelling stories, describe scenes with rich detail, and help users explore the creative and emotional aspects of visual content.",
|
229 |
+
}
|
230 |
+
|
231 |
+
# Determine which system prompt to use
|
232 |
+
if system_prompt_preset == "Custom":
|
233 |
+
system_prompt = custom_system_prompt
|
234 |
+
else:
|
235 |
+
system_prompt = preset_prompts.get(system_prompt_preset, custom_system_prompt)
|
236 |
+
|
237 |
logger.debug(
|
238 |
+
f"\n message: {message} \n history: {history} \n system_prompt_preset: {system_prompt_preset} \n "
|
239 |
+
f"system_prompt: {system_prompt} \n model_choice: {model_choice} \n max_new_tokens: {max_new_tokens} \n max_images: {max_images}"
|
240 |
)
|
241 |
|
242 |
selected_model = model_12 if model_choice == "Gemma 3 12B" else model_3n
|
|
|
290 |
),
|
291 |
multimodal=True,
|
292 |
additional_inputs=[
|
293 |
+
gr.Dropdown(
|
294 |
+
label="System Prompt Preset",
|
295 |
+
choices=[
|
296 |
+
"General Assistant",
|
297 |
+
"Document Analyzer",
|
298 |
+
"Visual Content Expert",
|
299 |
+
"Educational Tutor",
|
300 |
+
"Technical Reviewer",
|
301 |
+
"Creative Storyteller",
|
302 |
+
"Custom"
|
303 |
+
],
|
304 |
+
value="General Assistant",
|
305 |
+
info="Choose a preset or select 'Custom' to write your own"
|
306 |
+
),
|
307 |
+
gr.Textbox(
|
308 |
+
label="Custom System Prompt",
|
309 |
+
value="You are a helpful AI assistant capable of analyzing images, videos, and PDF documents. Provide clear, accurate, and helpful responses to user queries.",
|
310 |
+
lines=3,
|
311 |
+
info="Edit this field when 'Custom' is selected above, or modify any preset"
|
312 |
+
),
|
313 |
gr.Dropdown(
|
314 |
label="Model",
|
315 |
choices=["Gemma 3 12B", "Gemma 3n E4B"],
|
|
|
335 |
stop_btn=False,
|
336 |
)
|
337 |
|
338 |
+
# Add JavaScript to update custom prompt when preset changes
|
339 |
+
def update_custom_prompt(preset_choice):
|
340 |
+
preset_prompts = {
|
341 |
+
"General Assistant": "You are a helpful AI assistant capable of analyzing images, videos, and PDF documents. Provide clear, accurate, and helpful responses to user queries.",
|
342 |
+
|
343 |
+
"Document Analyzer": "You are a specialized document analysis assistant. Focus on extracting key information, summarizing content, and answering specific questions about uploaded documents. For PDFs, provide structured analysis including main topics, key points, and relevant details. For images containing text, perform OCR-like analysis.",
|
344 |
+
|
345 |
+
"Visual Content Expert": "You are an expert in visual content analysis. When analyzing images, provide detailed descriptions of visual elements, composition, colors, objects, people, and scenes. For videos, describe the sequence of events, movements, and changes between frames. Identify artistic techniques, styles, and visual storytelling elements.",
|
346 |
+
|
347 |
+
"Educational Tutor": "You are a patient and encouraging educational tutor. Break down complex concepts into simple, understandable explanations. When analyzing educational materials (images, videos, or documents), focus on learning objectives, key concepts, and provide additional context or examples to enhance understanding.",
|
348 |
+
|
349 |
+
"Technical Reviewer": "You are a technical expert specializing in analyzing technical documents, diagrams, code screenshots, and instructional videos. Provide detailed technical insights, identify potential issues, suggest improvements, and explain technical concepts with precision and accuracy.",
|
350 |
+
|
351 |
+
"Creative Storyteller": "You are a creative storyteller who brings visual content to life through engaging narratives. When analyzing images or videos, create compelling stories, describe scenes with rich detail, and help users explore the creative and emotional aspects of visual content.",
|
352 |
+
|
353 |
+
"Custom": ""
|
354 |
+
}
|
355 |
+
|
356 |
+
return preset_prompts.get(preset_choice, "")
|
357 |
+
|
358 |
+
# Connect the dropdown to update the textbox
|
359 |
+
with demo:
|
360 |
+
preset_dropdown = demo.additional_inputs[0]
|
361 |
+
custom_textbox = demo.additional_inputs[1]
|
362 |
+
preset_dropdown.change(
|
363 |
+
fn=update_custom_prompt,
|
364 |
+
inputs=[preset_dropdown],
|
365 |
+
outputs=[custom_textbox]
|
366 |
+
)
|
367 |
+
|
368 |
if __name__ == "__main__":
|
369 |
demo.launch()
|