Spaces:
Sleeping
Sleeping
hugohabicht01
commited on
Commit
·
4341bf2
1
Parent(s):
2383ea8
make prompts optional
Browse files
app.py
CHANGED
@@ -178,19 +178,19 @@ def run_model_inference(input_image_pil: Image.Image, prompt_text: str, system_p
|
|
178 |
|
179 |
|
180 |
@spaces.GPU(duration=90) # Request GPU for this function, allow up to 120 seconds
|
181 |
-
def analyze_image(input_image_pil: Image.Image, prompt_text: str, system_prompt_text: str):
|
182 |
"""
|
183 |
Analyzes the input image using the VLM, visualizes findings, and anonymizes.
|
184 |
"""
|
185 |
if input_image_pil is None:
|
186 |
raise gr.Error("Please upload an image.")
|
187 |
-
|
188 |
-
|
189 |
-
if
|
190 |
-
|
191 |
|
192 |
try:
|
193 |
-
raw_model_output, image_height, image_width = run_model_inference(input_image_pil,
|
194 |
except Exception as e:
|
195 |
print(f"Error during model inference: {e}")
|
196 |
print(traceback.format_exc())
|
@@ -281,9 +281,9 @@ with gr.Blocks() as demo:
|
|
281 |
with gr.Row():
|
282 |
with gr.Column(scale=1):
|
283 |
input_image = gr.Image(type="pil", label="Upload Image")
|
284 |
-
system_prompt_input = gr.Textbox(label="System Prompt", value=SYSTEM_PROMPT, lines=5, interactive=True) # New system prompt input
|
285 |
prompt_textbox = gr.Textbox(
|
286 |
-
label="Analysis Prompt", value=DEFAULT_PROMPT, lines=4
|
287 |
)
|
288 |
analyze_button = gr.Button("Analyze Image")
|
289 |
with gr.Column(scale=2):
|
|
|
178 |
|
179 |
|
180 |
@spaces.GPU(duration=90) # Request GPU for this function, allow up to 120 seconds
|
181 |
+
def analyze_image(input_image_pil: Image.Image, prompt_text: Optional[str] = None, system_prompt_text: Optional[str] = None):
|
182 |
"""
|
183 |
Analyzes the input image using the VLM, visualizes findings, and anonymizes.
|
184 |
"""
|
185 |
if input_image_pil is None:
|
186 |
raise gr.Error("Please upload an image.")
|
187 |
+
|
188 |
+
# Use default prompts if none are provided
|
189 |
+
final_prompt_text = prompt_text if prompt_text else DEFAULT_PROMPT
|
190 |
+
final_system_prompt_text = system_prompt_text if system_prompt_text else SYSTEM_PROMPT
|
191 |
|
192 |
try:
|
193 |
+
raw_model_output, image_height, image_width = run_model_inference(input_image_pil, final_prompt_text, final_system_prompt_text)
|
194 |
except Exception as e:
|
195 |
print(f"Error during model inference: {e}")
|
196 |
print(traceback.format_exc())
|
|
|
281 |
with gr.Row():
|
282 |
with gr.Column(scale=1):
|
283 |
input_image = gr.Image(type="pil", label="Upload Image")
|
284 |
+
system_prompt_input = gr.Textbox(label="System Prompt", value=SYSTEM_PROMPT, lines=5, interactive=True, value=None) # New system prompt input
|
285 |
prompt_textbox = gr.Textbox(
|
286 |
+
label="Analysis Prompt", value=DEFAULT_PROMPT, lines=4, value=None
|
287 |
)
|
288 |
analyze_button = gr.Button("Analyze Image")
|
289 |
with gr.Column(scale=2):
|