Spaces:
Sleeping
Sleeping
Nils Durner
commited on
Commit
·
a467dc2
1
Parent(s):
02f1bd2
multi-file upload
Browse files
app.py
CHANGED
@@ -49,31 +49,33 @@ def add_text(history, text):
|
|
49 |
history = history + [(text, None)]
|
50 |
return history, gr.Textbox(value="", interactive=False)
|
51 |
|
52 |
-
def add_file(history,
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
|
|
58 |
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
|
64 |
-
|
65 |
-
|
66 |
|
67 |
-
|
68 |
|
69 |
return history
|
70 |
|
71 |
-
def add_img(history,
|
72 |
-
|
73 |
-
|
74 |
-
|
|
|
75 |
|
76 |
-
|
77 |
|
78 |
return history
|
79 |
|
@@ -224,7 +226,7 @@ with gr.Blocks() as demo:
|
|
224 |
)
|
225 |
|
226 |
with gr.Row():
|
227 |
-
btn = gr.UploadButton("📁 Upload", size="sm")
|
228 |
img_btn = gr.UploadButton("🖼️ Upload", size="sm", file_types=["image"])
|
229 |
undo_btn = gr.Button("↩️ Undo")
|
230 |
undo_btn.click(undo, inputs=[chatbot], outputs=[chatbot])
|
|
|
49 |
history = history + [(text, None)]
|
50 |
return history, gr.Textbox(value="", interactive=False)
|
51 |
|
52 |
+
def add_file(history, files):
|
53 |
+
for file in files:
|
54 |
+
if file.name.endswith(".docx"):
|
55 |
+
content = process_docx(file.name)
|
56 |
+
else:
|
57 |
+
with open(file.name, mode="rb") as f:
|
58 |
+
content = f.read()
|
59 |
|
60 |
+
if isinstance(content, bytes):
|
61 |
+
content = content.decode('utf-8', 'replace')
|
62 |
+
else:
|
63 |
+
content = str(content)
|
64 |
|
65 |
+
fn = os.path.basename(file.name)
|
66 |
+
history = history + [(f'```{fn}\n{content}\n```', None)]
|
67 |
|
68 |
+
gr.Info(f"File added as {fn}")
|
69 |
|
70 |
return history
|
71 |
|
72 |
+
def add_img(history, files):
|
73 |
+
for file in files:
|
74 |
+
if log_to_console:
|
75 |
+
print(f"add_img {file.name}")
|
76 |
+
history = history + [(image_embed_prefix + file.name, None)]
|
77 |
|
78 |
+
gr.Info(f"Image added as {file.name}")
|
79 |
|
80 |
return history
|
81 |
|
|
|
226 |
)
|
227 |
|
228 |
with gr.Row():
|
229 |
+
btn = gr.UploadButton("📁 Upload", size="sm", file_count="multiple")
|
230 |
img_btn = gr.UploadButton("🖼️ Upload", size="sm", file_types=["image"])
|
231 |
undo_btn = gr.Button("↩️ Undo")
|
232 |
undo_btn.click(undo, inputs=[chatbot], outputs=[chatbot])
|