Update app.py
Browse files
app.py
CHANGED
@@ -89,48 +89,33 @@ def extract_info(image_path):
|
|
89 |
df_result = pd.DataFrame([flat_dict]).T.reset_index()
|
90 |
df_result.columns = ["Field", "Value"]
|
91 |
|
92 |
-
# CSV ํ์ผ๋ก ์ ์ฅ
|
93 |
-
tmp_dir = tempfile.mkdtemp()
|
94 |
-
csv_path = os.path.join(tmp_dir, "namecard_example.csv")
|
95 |
-
df_result.to_csv(csv_path, index=False)
|
96 |
|
97 |
-
return json_result, df_result
|
98 |
|
99 |
|
100 |
# ๐ง Gradio ์ธํฐํ์ด์ค ๊ตฌ์ฑ
|
101 |
with gr.Blocks() as demo:
|
102 |
gr.Markdown("## ๐ ๋ช
ํจ ์ ๋ณด ์๋ ์ถ์ถ๊ธฐ")
|
103 |
-
gr.Markdown("๋ช
ํจ ์ด๋ฏธ์ง๋ฅผ ์
๋ก๋ํ๋ฉด ์ ๋ณด๋ฅผ JSON๊ณผ ํ
์ด๋ธ ํ์์ผ๋ก
|
104 |
|
105 |
with gr.Row():
|
106 |
-
# ๐ค ์ฌ์ฉ์ ์
๋ ฅ (์ด๋ฏธ์ง ์
๋ก๋ ๋ฐ ๋ฒํผ)
|
107 |
with gr.Column():
|
108 |
image_input = gr.Image(type="filepath", label="๋ช
ํจ ์ด๋ฏธ์ง ์
๋ก๋")
|
109 |
extract_btn = gr.Button("๐ค ์ ๋ณด ์ถ์ถํ๊ธฐ")
|
110 |
|
111 |
-
# ๐ ์ถ๋ ฅ ์์ญ (JSON, ํ
์ด๋ธ, ๋ค์ด๋ก๋ ๋ฒํผ)
|
112 |
with gr.Column():
|
113 |
json_output = gr.Textbox(label="๐ ์ถ์ถ๋ JSON", lines=8)
|
114 |
table_output = gr.Dataframe(label="๐ ์ถ์ถ๋ ์ ๋ณด (ํ ํํ)", interactive=False)
|
115 |
-
download_btn = gr.Button("๐ฅ CSV ๋ค์ด๋ก๋ ๋ฐ๊ธฐ")
|
116 |
-
file_output = gr.File(label="", visible=False)
|
117 |
-
csv_output = gr.File(label="๐ฅ CSV ๋ค์ด๋ก๋", visible=True, interactive=False)
|
118 |
|
119 |
-
# ์ถ์ถ ํจ์ ์คํ
|
120 |
extract_btn.click(
|
121 |
-
fn=extract_info,
|
122 |
inputs=image_input,
|
123 |
-
outputs=[json_output, table_output
|
124 |
-
)
|
125 |
-
|
126 |
-
# ๋ฒํผ ๋๋ฅด๋ฉด file_output ๊ฐ์ csv_output์ ๋ณต์ฌ
|
127 |
-
download_btn.click(
|
128 |
-
fn=lambda path: gr.File.update(value=path),
|
129 |
-
inputs=file_output,
|
130 |
-
outputs=csv_output
|
131 |
)
|
132 |
|
133 |
|
|
|
134 |
# ์ฑ ์คํ
|
135 |
if __name__ == "__main__":
|
136 |
demo.launch()
|
|
|
89 |
df_result = pd.DataFrame([flat_dict]).T.reset_index()
|
90 |
df_result.columns = ["Field", "Value"]
|
91 |
|
|
|
|
|
|
|
|
|
92 |
|
93 |
+
return json_result, df_result
|
94 |
|
95 |
|
96 |
# ๐ง Gradio ์ธํฐํ์ด์ค ๊ตฌ์ฑ
|
97 |
with gr.Blocks() as demo:
|
98 |
gr.Markdown("## ๐ ๋ช
ํจ ์ ๋ณด ์๋ ์ถ์ถ๊ธฐ")
|
99 |
+
gr.Markdown("๋ช
ํจ ์ด๋ฏธ์ง๋ฅผ ์
๋ก๋ํ๋ฉด ์ ๋ณด๋ฅผ JSON๊ณผ ํ
์ด๋ธ ํ์์ผ๋ก ์ถ์ถํฉ๋๋ค.")
|
100 |
|
101 |
with gr.Row():
|
|
|
102 |
with gr.Column():
|
103 |
image_input = gr.Image(type="filepath", label="๋ช
ํจ ์ด๋ฏธ์ง ์
๋ก๋")
|
104 |
extract_btn = gr.Button("๐ค ์ ๋ณด ์ถ์ถํ๊ธฐ")
|
105 |
|
|
|
106 |
with gr.Column():
|
107 |
json_output = gr.Textbox(label="๐ ์ถ์ถ๋ JSON", lines=8)
|
108 |
table_output = gr.Dataframe(label="๐ ์ถ์ถ๋ ์ ๋ณด (ํ ํํ)", interactive=False)
|
|
|
|
|
|
|
109 |
|
110 |
+
# ๋ฒํผ ํด๋ฆญ ์ ์ ๋ณด ์ถ์ถ ํจ์ ์คํ
|
111 |
extract_btn.click(
|
112 |
+
fn=extract_info,
|
113 |
inputs=image_input,
|
114 |
+
outputs=[json_output, table_output]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
115 |
)
|
116 |
|
117 |
|
118 |
+
|
119 |
# ์ฑ ์คํ
|
120 |
if __name__ == "__main__":
|
121 |
demo.launch()
|