madhavkotecha commited on
Commit
69e1964
·
verified ·
1 Parent(s): 38eb8df

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -0
app.py CHANGED
@@ -7,6 +7,7 @@ import pandas as pd
7
  from nltk.translate import bleu_score
8
  from nltk.translate.bleu_score import SmoothingFunction
9
  import torch
 
10
 
11
  yolo_weights_path = "final_wts.pt"
12
 
@@ -183,3 +184,33 @@ logits_flattened = slogits.reshape(-1, slogits.shape[-1])
183
  processor.batch_decode([logits_flattened.argmax(-1)], skip_special_tokens=True)
184
 
185
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
  from nltk.translate import bleu_score
8
  from nltk.translate.bleu_score import SmoothingFunction
9
  import torch
10
+ import gradio as gr
11
 
12
  yolo_weights_path = "final_wts.pt"
13
 
 
184
  processor.batch_decode([logits_flattened.argmax(-1)], skip_special_tokens=True)
185
 
186
 
187
+ ---------------------------------------
188
+
189
+
190
+ def gradio_inference(image_path):
191
+ """
192
+ Function to handle inference and output the generated texts and final processed texts.
193
+ """
194
+ df, bounding_path, tokens, logits, gen_texts = inference(image_path, debug=False, return_texts='final_v2')
195
+
196
+ # Convert the DataFrame for final texts to a readable format
197
+ final_texts = df.to_string(index=False)
198
+
199
+ # Convert the list of generated texts into a readable string
200
+ gen_texts_output = '\n'.join(gen_texts)
201
+
202
+ return gen_texts_output, final_texts
203
+
204
+ image_input = gr.inputs.Image(type="filepath", label="Upload Image")
205
+ generated_output = gr.outputs.Textbox(label="Generated Texts")
206
+ final_output = gr.outputs.Textbox(label="Final Processed Texts")
207
+
208
+ interface = gr.Interface(
209
+ fn=gradio_inference,
210
+ inputs=image_input,
211
+ outputs=[generated_output, final_output],
212
+ title="OCR using LLMs",
213
+ description="Upload an image and get generated and final processed texts",
214
+ )
215
+
216
+ interface.launch()