Spaces:
Paused
Paused
Commit Β·
d28fe2d
1
Parent(s): 286f89b
Update app.py
Browse files
app.py
CHANGED
|
@@ -39,26 +39,18 @@ def analyze(image: Image.Image, prompt: str = "What's happening with my skin?"):
|
|
| 39 |
],
|
| 40 |
}
|
| 41 |
]
|
| 42 |
-
|
| 43 |
text = processor.apply_chat_template(
|
| 44 |
messages, tokenize=False, add_generation_prompt=True
|
| 45 |
)
|
| 46 |
image_inputs, _ = process_vision_info(messages)
|
| 47 |
-
|
| 48 |
inputs = processor(
|
| 49 |
-
text=[text],
|
| 50 |
-
images=image_inputs,
|
| 51 |
-
return_tensors="pt"
|
| 52 |
).to("cuda")
|
| 53 |
|
| 54 |
with torch.inference_mode():
|
| 55 |
generated_ids = model.generate(
|
| 56 |
-
**inputs,
|
| 57 |
-
max_new_tokens=256,
|
| 58 |
-
do_sample=True,
|
| 59 |
-
temperature=0.2
|
| 60 |
)
|
| 61 |
-
|
| 62 |
output_ids = generated_ids[0, inputs.input_ids.shape[1]:]
|
| 63 |
return processor.decode(output_ids, skip_special_tokens=True)
|
| 64 |
|
|
@@ -79,7 +71,7 @@ async def analyze_endpoint(
|
|
| 79 |
result = analyze(pil_image, prompt)
|
| 80 |
return JSONResponse({"analysis": result})
|
| 81 |
|
| 82 |
-
# ββ Gradio
|
| 83 |
demo = gr.Interface(
|
| 84 |
fn=analyze,
|
| 85 |
inputs=[
|
|
@@ -91,5 +83,4 @@ demo = gr.Interface(
|
|
| 91 |
description="Upload a skin image to get an AI-powered dermatological analysis."
|
| 92 |
)
|
| 93 |
|
| 94 |
-
|
| 95 |
-
app = gr.mount_gradio_app(fapi, demo, path="/")
|
|
|
|
| 39 |
],
|
| 40 |
}
|
| 41 |
]
|
|
|
|
| 42 |
text = processor.apply_chat_template(
|
| 43 |
messages, tokenize=False, add_generation_prompt=True
|
| 44 |
)
|
| 45 |
image_inputs, _ = process_vision_info(messages)
|
|
|
|
| 46 |
inputs = processor(
|
| 47 |
+
text=[text], images=image_inputs, return_tensors="pt"
|
|
|
|
|
|
|
| 48 |
).to("cuda")
|
| 49 |
|
| 50 |
with torch.inference_mode():
|
| 51 |
generated_ids = model.generate(
|
| 52 |
+
**inputs, max_new_tokens=256, do_sample=True, temperature=0.2
|
|
|
|
|
|
|
|
|
|
| 53 |
)
|
|
|
|
| 54 |
output_ids = generated_ids[0, inputs.input_ids.shape[1]:]
|
| 55 |
return processor.decode(output_ids, skip_special_tokens=True)
|
| 56 |
|
|
|
|
| 71 |
result = analyze(pil_image, prompt)
|
| 72 |
return JSONResponse({"analysis": result})
|
| 73 |
|
| 74 |
+
# ββ Gradio mounted ONCE onto FastAPI βββββββββββββββββββββββββββββββββββββββββ
|
| 75 |
demo = gr.Interface(
|
| 76 |
fn=analyze,
|
| 77 |
inputs=[
|
|
|
|
| 83 |
description="Upload a skin image to get an AI-powered dermatological analysis."
|
| 84 |
)
|
| 85 |
|
| 86 |
+
gr.mount_gradio_app(fapi, demo, path="/ui")
|
|
|