kmkarakaya commited on
Commit
0942172
·
verified ·
1 Parent(s): fe7bca5

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +54 -0
app.py ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import os
3
+ from typing import List
4
+
5
+ def upload_pdfs(files: List[gr.File]):
6
+ """
7
+ Saves the uploaded PDF files to a directory.
8
+ """
9
+ os.makedirs("uploaded_pdfs", exist_ok=True)
10
+ for file in files:
11
+ file_path = os.path.join("uploaded_pdfs", file.name)
12
+ file.save(file_path)
13
+ return f"Saved {len(files)} PDF files to the 'uploaded_pdfs' directory."
14
+
15
+ def chat_with_rag(question: str):
16
+ """
17
+ Interacts with the rag system and returns the answer.
18
+ """
19
+ # Implement the logic to interact with the rag system
20
+ answer = f"The answer to your question '{question}' is: This is a placeholder response. You will need to implement the actual logic to interact with the rag system."
21
+ return answer
22
+
23
+ def show_chat_history():
24
+ """
25
+ Displays the chat history.
26
+ """
27
+ # Implement the logic to fetch and display the chat history
28
+ chat_history = "This is a placeholder for the chat history. You will need to implement the logic to fetch and display the actual chat history."
29
+ return chat_history
30
+
31
+ def create_gradio_interface():
32
+ with gr.Blocks(title="Rag System UI", theme=gr.themes.Soft()) as demo:
33
+ gr.Markdown("# Rag System UI")
34
+
35
+ with gr.Tab("File Upload"):
36
+ file_uploader = gr.File(label="Upload PDFs", file_count="multiple")
37
+ upload_button = gr.Button("Upload PDFs")
38
+ upload_button.click(upload_pdfs, inputs=file_uploader, outputs=gr.Textbox())
39
+
40
+ with gr.Tab("Chat"):
41
+ chat_input = gr.Textbox(label="Ask a question")
42
+ chat_button = gr.Button("Get Answer")
43
+ chat_output = gr.Textbox(label="Answer")
44
+ chat_button.click(chat_with_rag, inputs=chat_input, outputs=chat_output)
45
+
46
+ with gr.Tab("History"):
47
+ history_button = gr.Button("Show Chat History")
48
+ history_output = gr.Textbox(label="Chat History")
49
+ history_button.click(show_chat_history, outputs=history_output)
50
+
51
+ return demo
52
+
53
+ if __name__ == "__main__":
54
+ create_gradio_interface().launch()