Frank Pacini commited on
Commit
fcfec80
1 Parent(s): ba16020

fixed custom File component

Browse files
Files changed (2) hide show
  1. CustomFile.py +16 -15
  2. app.py +2 -2
CustomFile.py CHANGED
@@ -1,19 +1,20 @@
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 postprocess(self, y: str) -> Dict:
13
- # res = super().postprocess(y)
14
- # if res is not None:
15
- # res['data'] = encode_file_to_base64(res['name'])
16
- # return res
17
- def dummy(self):
18
- return
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=[gr.File(), gr.Dataframe(max_rows = 10),gr.Dataframe(max_rows = 10)])
35
- iface.launch(show_error=True, debug=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)