Update src/interface.py
Browse files- src/interface.py +28 -34
src/interface.py
CHANGED
@@ -1,22 +1,20 @@
|
|
1 |
import csv
|
2 |
import gradio as gr
|
3 |
|
4 |
-
#
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
return csvfile
|
20 |
|
21 |
# Gradio application setup
|
22 |
def create_demo():
|
@@ -73,26 +71,22 @@ def create_demo():
|
|
73 |
submit_button = gr.Button('Send')
|
74 |
with gr.Column(scale=0.20):
|
75 |
uploaded_pdf = gr.UploadButton("📁 Upload PDF", file_types=[".pdf"], elem_id='upload_pdf')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
76 |
|
77 |
-
|
78 |
-
|
79 |
-
fn=export_conversations,
|
80 |
-
inputs="conversations",
|
81 |
-
outputs=Output.File(type="csv"),
|
82 |
-
title="Export Conversations",
|
83 |
-
description="Export conversations as a CSV file"
|
84 |
-
)
|
85 |
-
|
86 |
-
# Add a download button to trigger the export
|
87 |
-
download_button = Button("Download Conversations as CSV")
|
88 |
-
|
89 |
-
# Add the components to the interface
|
90 |
-
iface.launch(inputs=["conversations"], outputs="file", api_name="export_conversations", api_open_browser=False, flagging_callback=None, analytics_enabled=False, enable_queue=True, show_error=True, allow_screenshot=True, allow_flagging=True)
|
91 |
-
|
92 |
-
|
93 |
-
return demo, chat_history, show_img, text_input, submit_button, uploaded_pdf, slider_chunk_size,slider_overlap_percentage,slider_temp,slider_k
|
94 |
|
95 |
if __name__ == '__main__':
|
96 |
-
demo, chatbot, show_img, text_input, submit_button, uploaded_pdf, slider_chunk_size,slider_overlap_percentage,slider_temp,slider_k = create_demo()
|
97 |
demo.queue()
|
98 |
demo.launch()
|
|
|
1 |
import csv
|
2 |
import gradio as gr
|
3 |
|
4 |
+
#NEW
|
5 |
+
# Function to update chat history and conversation history
|
6 |
+
def update_chat_history(user_input, bot_response):
|
7 |
+
chat_history.update(value=chat_history.value + [(user_input, bot_response)])
|
8 |
+
conversation_history.append([user_input, bot_response])
|
9 |
+
|
10 |
+
# Function to download conversation history
|
11 |
+
def download_conversation_history():
|
12 |
+
with open('conversation_history.csv', 'w', newline='') as file:
|
13 |
+
writer = csv.writer(file)
|
14 |
+
writer.writerow(["User Input", "Bot Response"])
|
15 |
+
writer.writerows(conversation_history)
|
16 |
+
return "conversation_history.csv"
|
17 |
+
#NEW
|
|
|
|
|
18 |
|
19 |
# Gradio application setup
|
20 |
def create_demo():
|
|
|
71 |
submit_button = gr.Button('Send')
|
72 |
with gr.Column(scale=0.20):
|
73 |
uploaded_pdf = gr.UploadButton("📁 Upload PDF", file_types=[".pdf"], elem_id='upload_pdf')
|
74 |
+
#NEW
|
75 |
+
with gr.Colum(scale=0.20):
|
76 |
+
download_button = gr.Button('Download Conversation History')
|
77 |
+
|
78 |
+
# Conversation History
|
79 |
+
conversation_history = []
|
80 |
+
|
81 |
+
# Event listeners
|
82 |
+
submit_button.click(fn=update_chat_history, inputs=[text_input, chat_history], outputs=chat_history)
|
83 |
+
download_button.click(fn=download_conversation_history, outputs="download")
|
84 |
+
#NEW
|
85 |
|
86 |
+
|
87 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
88 |
|
89 |
if __name__ == '__main__':
|
90 |
+
demo, chatbot, show_img, text_input, submit_button, uploaded_pdf, slider_chunk_size,slider_overlap_percentage,slider_temp,slider_k, download_button = create_demo()
|
91 |
demo.queue()
|
92 |
demo.launch()
|