Spaces:
Runtime error
Runtime error
| import gradio as gr | |
| from custom.clip_ebc_onnx import ClipEBCOnnx | |
| import numpy as np | |
| import matplotlib.pyplot as plt | |
| # ONNX ๋ชจ๋ธ ์ด๊ธฐํ | |
| model = ClipEBCOnnx() | |
| def predict_crowd(image): | |
| """ | |
| ์ด๋ฏธ์ง๋ฅผ ๋ฐ์์ ๊ตฐ์ค ์๋ฅผ ์์ธกํ๊ณ ์๊ฐํ ๊ฒฐ๊ณผ๋ฅผ ๋ฐํํฉ๋๋ค. | |
| Args: | |
| image: Gradio์์ ๋ฐ์ ์ด๋ฏธ์ง (numpy array) | |
| Returns: | |
| tuple: (์์ธก๋ ๊ตฐ์ค ์, ๋ฐ๋ ๋งต ์๊ฐํ, ์ ์๊ฐํ) | |
| """ | |
| count = model.predict(image) | |
| # ๋ฐ๋ ๋งต ์๊ฐํ | |
| fig_density, density_map = model.visualize_density_map() | |
| plt.close(fig_density) # ๋ฉ๋ชจ๋ฆฌ ๋์ ๋ฐฉ์ง | |
| # ์ ์๊ฐํ | |
| canvas, dot_map = model.visualize_dots() | |
| plt.close(canvas.figure) | |
| return ( | |
| f"์์ธก๋ ๊ตฐ์ค ์: {count:.1f}๋ช ", | |
| density_map, | |
| dot_map | |
| ) | |
| with gr.Blocks(title="CLIP-EBC Crowd Counter") as app: | |
| gr.Markdown("# CLIP-EBC Crowd Counter") | |
| gr.Markdown("์ด๋ฏธ์ง๋ฅผ ์ ๋ก๋ํ์ฌ ๊ตฐ์ค ์๋ฅผ ์์ธกํ๊ณ ์๊ฐํํฉ๋๋ค.") | |
| with gr.Row(): | |
| input_image = gr.Image(type="numpy", label="์ ๋ ฅ ์ด๋ฏธ์ง") | |
| with gr.Row(): | |
| predict_btn = gr.Button("์์ธก", variant="primary") | |
| with gr.Row(): | |
| count_text = gr.Textbox(label="์์ธก ๊ฒฐ๊ณผ") | |
| with gr.Row(): | |
| with gr.Column(): | |
| density_output = gr.Image(label="๋ฐ๋ ๋งต") | |
| with gr.Column(): | |
| dots_output = gr.Image(label="์ ์๊ฐํ") | |
| predict_btn.click( | |
| fn=predict_crowd, | |
| inputs=input_image, | |
| outputs=[count_text, density_output, dots_output] | |
| ) | |
| if __name__ == "__main__": | |
| app.launch(share=False) |