Hi, I would like to allow users to use the File Manager to select a generic file (e.g. a Word document), so that the filepath for that file is passed to a function as a string, instead of passing a tempfile object.
E.g. User selects a Word document, the filepath for that document is then passed to a function which loads and processes the text from the document before returning some output.
I’ve tried using gr.File(), but this only seems to pass the actual file as a tempfile. I think gr.Image(type=“filepath”) does what I want, but this only works for images, not other filetypes.
Any help would be really appreciated!
Example code:
demo = gr.Blocks()
with demo:
gr.Markdown("Upload a document to extract questions and get suggested responses.")
with gr.Row():
file_input = gr.File()
file_output = gr.Textbox(label="Questions")
file_button = gr.Button("Extract Questions")
question_box = gr.Textbox(label="Question")
suggest_button = gr.Button("Suggest Answers")
suggest_output = gr.Textbox(label="Suggested Answer")
file_button.click(
fn=lambda x : extract_questions(document=x),
inputs=file_input,
outputs=file_output
)
suggest_button.click(
fn=suggest_answer,
inputs=question_box,
outputs=suggest_output)
demo.launch()