Spaces:
Build error
Build error
Frank Pacini
commited on
Commit
·
fcfec80
1
Parent(s):
ba16020
fixed custom File component
Browse files- CustomFile.py +16 -15
- app.py +2 -2
CustomFile.py
CHANGED
@@ -1,19 +1,20 @@
|
|
1 |
import gradio as gr
|
2 |
-
|
3 |
-
|
4 |
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
|
11 |
class CustomFile(gr.File):
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
|
|
|
1 |
import gradio as gr
|
2 |
+
from typing import Dict
|
3 |
+
import base64
|
4 |
|
5 |
+
def encode_file_to_base64(f):
|
6 |
+
with open(f, "rb") as file:
|
7 |
+
encoded_string = base64.b64encode(file.read())
|
8 |
+
base64_str = str(encoded_string, "utf-8")
|
9 |
+
return base64_str
|
10 |
|
11 |
class CustomFile(gr.File):
|
12 |
+
def get_block_name(self) -> str:
|
13 |
+
return "file"
|
14 |
+
|
15 |
+
def postprocess(self, y: str) -> Dict:
|
16 |
+
res = super().postprocess(y)
|
17 |
+
if res is not None:
|
18 |
+
for file in res:
|
19 |
+
file['data'] = encode_file_to_base64(file['name'])
|
20 |
+
return res
|
app.py
CHANGED
@@ -31,5 +31,5 @@ def predict(video_path, frames):
|
|
31 |
return ([video_path, video_path, audio_path], df, df)
|
32 |
|
33 |
|
34 |
-
iface = gr.Interface(predict, inputs= [gr.Video(),gr.Slider(1, 100, value=15)], outputs=[
|
35 |
-
iface.launch(show_error=True
|
|
|
31 |
return ([video_path, video_path, audio_path], df, df)
|
32 |
|
33 |
|
34 |
+
iface = gr.Interface(predict, inputs= [gr.Video(), gr.Slider(1, 100, value=15)], outputs=[CustomFile(), gr.Dataframe(max_rows = 10),gr.Dataframe(max_rows = 10)])
|
35 |
+
iface.launch(show_error=True)
|