wanda222 commited on
Commit
8f43717
ยท
verified ยท
1 Parent(s): d041ede

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -21
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, csv_path
98
 
99
 
100
  # ๐Ÿ”ง Gradio ์ธํ„ฐํŽ˜์ด์Šค ๊ตฌ์„ฑ
101
  with gr.Blocks() as demo:
102
  gr.Markdown("## ๐Ÿ“‡ ๋ช…ํ•จ ์ •๋ณด ์ž๋™ ์ถ”์ถœ๊ธฐ")
103
- gr.Markdown("๋ช…ํ•จ ์ด๋ฏธ์ง€๋ฅผ ์—…๋กœ๋“œํ•˜๋ฉด ์ •๋ณด๋ฅผ JSON๊ณผ ํ…Œ์ด๋ธ” ํ˜•์‹์œผ๋กœ ์ถ”์ถœํ•˜๊ณ , CSV๋กœ ์ €์žฅํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.")
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, file_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()