Spaces:
Runtime error
Runtime error
stupidog04
commited on
Commit
•
97a7e85
1
Parent(s):
e72880c
Update app.py
Browse files
app.py
CHANGED
@@ -10,11 +10,7 @@ import cv2
|
|
10 |
import pandas as pd
|
11 |
from transformers import TrOCRProcessor, VisionEncoderDecoderModel
|
12 |
import matplotlib.pyplot as plt
|
13 |
-
|
14 |
-
|
15 |
-
#torch.hub.download_url_to_file('https://github.com/AaronCWacker/Yggdrasil/blob/main/images/BeautyIsTruthTruthisBeauty.JPG', 'BeautyIsTruthTruthisBeauty.JPG')
|
16 |
-
#torch.hub.download_url_to_file('https://github.com/AaronCWacker/Yggdrasil/blob/main/images/PleaseRepeatLouder.jpg', 'PleaseRepeatLouder.jpg')
|
17 |
-
#torch.hub.download_url_to_file('https://github.com/AaronCWacker/Yggdrasil/blob/main/images/ProhibitedInWhiteHouse.JPG', 'ProhibitedInWhiteHouse.JPG')
|
18 |
|
19 |
torch.hub.download_url_to_file('https://raw.githubusercontent.com/AaronCWacker/Yggdrasil/master/images/20-Books.jpg','20-Books.jpg')
|
20 |
torch.hub.download_url_to_file('https://github.com/JaidedAI/EasyOCR/raw/master/examples/english.png', 'COVID.png')
|
@@ -199,9 +195,26 @@ def inference(video, lang, full_scan, number_filter, use_trocr, time_step, perio
|
|
199 |
df_list.append({"Box": f"", "Time (s)": "", "Text": ""})
|
200 |
df = pd.concat([pd.DataFrame(df_list)])
|
201 |
|
202 |
-
#
|
203 |
plot_fig = plot_temporal_profile(temporal_profiles)
|
204 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
205 |
|
206 |
|
207 |
title = '🖼️Video to Multilingual OCR👁️Gradio'
|
@@ -240,8 +253,9 @@ gr.Interface(
|
|
240 |
[
|
241 |
gr.outputs.Video(label='Output Video'),
|
242 |
gr.outputs.Image(label='Output Preview', type='numpy'),
|
243 |
-
gr.Plot(label='Temporal Profile'),
|
244 |
-
gr.outputs.
|
|
|
245 |
],
|
246 |
title=title,
|
247 |
description=description,
|
|
|
10 |
import pandas as pd
|
11 |
from transformers import TrOCRProcessor, VisionEncoderDecoderModel
|
12 |
import matplotlib.pyplot as plt
|
13 |
+
import io
|
|
|
|
|
|
|
|
|
14 |
|
15 |
torch.hub.download_url_to_file('https://raw.githubusercontent.com/AaronCWacker/Yggdrasil/master/images/20-Books.jpg','20-Books.jpg')
|
16 |
torch.hub.download_url_to_file('https://github.com/JaidedAI/EasyOCR/raw/master/examples/english.png', 'COVID.png')
|
|
|
195 |
df_list.append({"Box": f"", "Time (s)": "", "Text": ""})
|
196 |
df = pd.concat([pd.DataFrame(df_list)])
|
197 |
|
198 |
+
# Convert the Matplotlib plot to a NumPy array
|
199 |
plot_fig = plot_temporal_profile(temporal_profiles)
|
200 |
+
buf = io.BytesIO()
|
201 |
+
plot_fig.savefig(buf, format='png')
|
202 |
+
buf.seek(0)
|
203 |
+
plot_image = PIL.Image.open(buf)
|
204 |
+
|
205 |
+
# Resize the image to fit the width of the returned image
|
206 |
+
im_width, im_height = im.size
|
207 |
+
plot_width, plot_height = plot_image.size
|
208 |
+
new_plot_height = int(plot_height * im_width / plot_width)
|
209 |
+
resized_plot_image = plot_image.resize((im_width, new_plot_height), PIL.Image.ANTIALIAS)
|
210 |
+
|
211 |
+
# Convert the resized image to a NumPy array
|
212 |
+
plot_np = np.array(resized_plot_image)
|
213 |
+
|
214 |
+
# Close the buffer
|
215 |
+
buf.close()
|
216 |
+
|
217 |
+
return output, im, plot_np, df # Change this line
|
218 |
|
219 |
|
220 |
title = '🖼️Video to Multilingual OCR👁️Gradio'
|
|
|
253 |
[
|
254 |
gr.outputs.Video(label='Output Video'),
|
255 |
gr.outputs.Image(label='Output Preview', type='numpy'),
|
256 |
+
# gr.Plot(label='Temporal Profile'),
|
257 |
+
gr.outputs.Image(label='Temporal Profile', type='numpy'),
|
258 |
+
gr.outputs.Dataframe(headers=['Box', 'Time (s)', 'Text'], type='pandas')
|
259 |
],
|
260 |
title=title,
|
261 |
description=description,
|