Update app.py
Browse files
app.py
CHANGED
|
@@ -226,4 +226,73 @@ def process_image(input_image):
|
|
| 226 |
except Exception as e:
|
| 227 |
return None, None, f"❌ خطا: {str(e)}"
|
| 228 |
|
| 229 |
-
# ادامه کد Gradio مشابه قبل...
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 226 |
except Exception as e:
|
| 227 |
return None, None, f"❌ خطا: {str(e)}"
|
| 228 |
|
| 229 |
+
# ادامه کد Gradio مشابه قبل...
|
| 230 |
+
|
| 231 |
+
# ایجاد اینترفیس Gradio
|
| 232 |
+
with gr.Blocks(title="CelebAMask-HQ Face Parsing", theme=gr.themes.Soft()) as demo:
|
| 233 |
+
gr.Markdown("""
|
| 234 |
+
# 🎭 CelebAMask-HQ Face Parsing Demo
|
| 235 |
+
**آپلود یک تصویر صورت و دریافت خروجی Face Parsing**
|
| 236 |
+
|
| 237 |
+
این مدل صورت را به 19 بخش مختلف تقسیم میکند (پوست، چشم، ابرو، بینی، دهان، مو و ...)
|
| 238 |
+
""")
|
| 239 |
+
|
| 240 |
+
with gr.Row():
|
| 241 |
+
with gr.Column():
|
| 242 |
+
input_image = gr.Image(
|
| 243 |
+
label="📷 تصویر ورودی",
|
| 244 |
+
type="filepath",
|
| 245 |
+
sources=["upload"],
|
| 246 |
+
height=300
|
| 247 |
+
)
|
| 248 |
+
process_btn = gr.Button("🚀 پردازش تصویر", variant="primary", size="lg")
|
| 249 |
+
|
| 250 |
+
with gr.Accordion("ℹ️ وضعیت برنامه", open=False):
|
| 251 |
+
status_display = gr.Markdown(f"""
|
| 252 |
+
**وضعیت:**
|
| 253 |
+
- 🎯 مدل: {'✅ لود شده' if success else '❌ خطا در لود'}
|
| 254 |
+
- 💻 دستگاه: `{device}`
|
| 255 |
+
- 📦 ماژولها: {'✅ ایمپورت شده' if IMPORT_SUCCESS else '❌ خطا در ایمپورت'}
|
| 256 |
+
- 🗂️ کلاسها: {len(CELEBA_CLASSES)}
|
| 257 |
+
""")
|
| 258 |
+
|
| 259 |
+
with gr.Column():
|
| 260 |
+
output_blended = gr.Image(
|
| 261 |
+
label="🎨 نتیجه ترکیبی (تصویر + ماسک)",
|
| 262 |
+
height=300
|
| 263 |
+
)
|
| 264 |
+
output_mask = gr.Image(
|
| 265 |
+
label="🎭 ماسک سگمنتیشن",
|
| 266 |
+
height=300
|
| 267 |
+
)
|
| 268 |
+
|
| 269 |
+
with gr.Row():
|
| 270 |
+
info_output = gr.Textbox(
|
| 271 |
+
label="📊 اطلاعات پردازش",
|
| 272 |
+
lines=3,
|
| 273 |
+
max_lines=6
|
| 274 |
+
)
|
| 275 |
+
|
| 276 |
+
with gr.Row():
|
| 277 |
+
gr.HTML(create_legend())
|
| 278 |
+
|
| 279 |
+
# اتصال رویدادها
|
| 280 |
+
process_btn.click(
|
| 281 |
+
fn=process_image,
|
| 282 |
+
inputs=[input_image],
|
| 283 |
+
outputs=[output_blended, output_mask, info_output]
|
| 284 |
+
)
|
| 285 |
+
|
| 286 |
+
input_image.upload(
|
| 287 |
+
fn=process_image,
|
| 288 |
+
inputs=[input_image],
|
| 289 |
+
outputs=[output_blended, output_mask, info_output]
|
| 290 |
+
)
|
| 291 |
+
|
| 292 |
+
if __name__ == "__main__":
|
| 293 |
+
print("🚀 Starting Face Parsing Application...")
|
| 294 |
+
demo.launch(
|
| 295 |
+
server_name="0.0.0.0",
|
| 296 |
+
server_port=7860,
|
| 297 |
+
share=False
|
| 298 |
+
)
|