Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -553,11 +553,24 @@ class Gradio_Events:
|
|
| 553 |
value=state_value)
|
| 554 |
|
| 555 |
@staticmethod
|
| 556 |
-
def preview_uploaded_file(uploaded_file_value):
|
| 557 |
if not uploaded_file_value:
|
| 558 |
-
return
|
|
|
|
|
|
|
|
|
|
|
|
|
| 559 |
uploaded_file = load_context_file(uploaded_file_value)
|
| 560 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 561 |
|
| 562 |
@staticmethod
|
| 563 |
def remove_uploaded_file(state_value):
|
|
@@ -807,9 +820,12 @@ with gr.Blocks(css=css, fill_width=True) as demo:
|
|
| 807 |
clear_btn.click(fn=Gradio_Events.clear_conversation_history,
|
| 808 |
inputs=[state],
|
| 809 |
outputs=[chatbot, state])
|
| 810 |
-
context_file.change(
|
| 811 |
-
|
| 812 |
-
|
|
|
|
|
|
|
|
|
|
| 813 |
remove_file_btn.click(fn=Gradio_Events.remove_uploaded_file,
|
| 814 |
inputs=[state],
|
| 815 |
outputs=[context_file, file_status, state])
|
|
|
|
| 553 |
value=state_value)
|
| 554 |
|
| 555 |
@staticmethod
|
| 556 |
+
def preview_uploaded_file(uploaded_file_value, state_value):
|
| 557 |
if not uploaded_file_value:
|
| 558 |
+
return (
|
| 559 |
+
gr.update(value="No file uploaded"),
|
| 560 |
+
gr.update(value=state_value)
|
| 561 |
+
)
|
| 562 |
+
|
| 563 |
uploaded_file = load_context_file(uploaded_file_value)
|
| 564 |
+
|
| 565 |
+
# Store it into the active conversation state immediately
|
| 566 |
+
conv_id = state_value.get("conversation_id")
|
| 567 |
+
if conv_id:
|
| 568 |
+
state_value["conversation_contexts"][conv_id]["settings"]["uploaded_file"] = uploaded_file
|
| 569 |
+
|
| 570 |
+
return (
|
| 571 |
+
gr.update(value=format_file_status(uploaded_file)),
|
| 572 |
+
gr.update(value=state_value)
|
| 573 |
+
)
|
| 574 |
|
| 575 |
@staticmethod
|
| 576 |
def remove_uploaded_file(state_value):
|
|
|
|
| 820 |
clear_btn.click(fn=Gradio_Events.clear_conversation_history,
|
| 821 |
inputs=[state],
|
| 822 |
outputs=[chatbot, state])
|
| 823 |
+
context_file.change(
|
| 824 |
+
fn=Gradio_Events.preview_uploaded_file,
|
| 825 |
+
inputs=[context_file, state],
|
| 826 |
+
outputs=[file_status, state]
|
| 827 |
+
)
|
| 828 |
+
|
| 829 |
remove_file_btn.click(fn=Gradio_Events.remove_uploaded_file,
|
| 830 |
inputs=[state],
|
| 831 |
outputs=[context_file, file_status, state])
|