sotirios-slv commited on
Commit
a0f2182
1 Parent(s): 3b925dc

Updated File download to output to excel worksheets

Browse files
Files changed (1) hide show
  1. app.py +11 -6
app.py CHANGED
@@ -42,15 +42,20 @@ def run(image, lang="eng"):
42
 
43
  def download_output(ocr_text: str, named_entities: str, image_name="test"):
44
  try:
45
- columns = ["OCR text", "Named entities"]
46
  named_entities_list = named_entities.split("\n")
47
- data = {ocr_text: named_entities_list}
48
  now = datetime.now()
49
  datetime_now = now.strftime("%Y%m%d_%H%M%S")
50
- output_file = f"analysed_{image_name}_{datetime_now}.csv"
51
- output_df = pd.DataFrame(data=data, columns=columns)
52
- output_df.to_csv(output_file, index=False)
 
 
 
53
 
 
 
 
54
  return output_file
55
 
56
  except Exception as e:
@@ -65,7 +70,7 @@ with gr.Blocks() as demo:
65
  lang = gr.Dropdown(choices, value="eng")
66
  btn = gr.Button("Run")
67
  # image_name = "Test"
68
- print("image_in", image_in)
69
  with gr.Column():
70
  ocr_text = gr.TextArea(label="OCR output")
71
  with gr.Column():
 
42
 
43
  def download_output(ocr_text: str, named_entities: str, image_name="test"):
44
  try:
 
45
  named_entities_list = named_entities.split("\n")
46
+
47
  now = datetime.now()
48
  datetime_now = now.strftime("%Y%m%d_%H%M%S")
49
+ output_file = f"{image_name}_{datetime_now}.xlsx"
50
+
51
+ ocr_df = pd.Series(ocr_text)
52
+ print("OCR ", ocr_df)
53
+ ner_df = pd.Series(named_entities_list)
54
+ print("NER ", ner_df)
55
 
56
+ with pd.ExcelWriter(output_file) as writer:
57
+ ocr_df.to_excel(writer, sheet_name="OCR text")
58
+ ner_df.to_excel(writer, sheet_name="Named entities")
59
  return output_file
60
 
61
  except Exception as e:
 
70
  lang = gr.Dropdown(choices, value="eng")
71
  btn = gr.Button("Run")
72
  # image_name = "Test"
73
+ print("image_in", image_in.name)
74
  with gr.Column():
75
  ocr_text = gr.TextArea(label="OCR output")
76
  with gr.Column():