zamal commited on
Commit
d769ce2
Β·
verified Β·
1 Parent(s): b40107a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +53 -34
app.py CHANGED
@@ -1,37 +1,56 @@
1
  import os
2
- import gradio as gr
 
 
3
  from rag_utility import process_document_to_chromadb, answer_question
4
 
5
- def process_and_store_file(file):
6
- if file is not None:
7
- working_dir = os.getcwd()
8
- save_path = os.path.join(working_dir, os.path.basename(file))
9
- with open(save_path, "wb") as f:
10
- f.write(file.read())
11
- process_document_to_chromadb(save_path)
12
- return "Document Processed Successfully"
13
- return "No file uploaded."
14
-
15
- def get_answers(question):
16
- if not question.strip():
17
- return "Please enter a question.", "Please enter a question."
18
- answer = answer_question(question)
19
- return answer["answer_deepseek"], answer["answer_llama3"]
20
-
21
- with gr.Blocks() as demo:
22
- gr.Markdown("# πŸ‹ DeepSeek-R1 vs πŸ¦™ Llama-3")
23
- with gr.Row():
24
- file_input = gr.File(label="Upload a PDF file", file_types=[".pdf"], type="filepath")
25
- process_button = gr.Button("Process Document")
26
- status_output = gr.Textbox(label="Status", interactive=False)
27
- process_button.click(process_and_store_file, inputs=file_input, outputs=status_output)
28
-
29
- question_input = gr.Textbox(label="Ask your question from the document")
30
- answer_button = gr.Button("Answer")
31
- with gr.Row():
32
- deepseek_output = gr.Markdown("### DeepSeek-r1 Response")
33
- llama3_output = gr.Markdown("### Llama-3 Response")
34
-
35
- answer_button.click(get_answers, inputs=question_input, outputs=[deepseek_output, llama3_output])
36
-
37
- demo.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import os
2
+
3
+ import streamlit as st
4
+
5
  from rag_utility import process_document_to_chromadb, answer_question
6
 
7
+
8
+ # Set working directory (optional, ensures saving in project dir)
9
+ working_dir = os.getcwd()
10
+
11
+ st.title("πŸ‹ DeepSeek-R1 vs πŸ¦™ Llama-3")
12
+
13
+ # File uploader
14
+ uploaded_file = st.file_uploader("Upload a PDF file", type=["pdf"])
15
+
16
+ if uploaded_file is not None:
17
+ # Define save path
18
+ save_path = os.path.join(working_dir, uploaded_file.name)
19
+ # Save file
20
+ with open(save_path, "wb") as f:
21
+ f.write(uploaded_file.getbuffer())
22
+
23
+ process_documents = process_document_to_chromadb(uploaded_file.name)
24
+ st.info("Document Processed Successfully")
25
+
26
+
27
+ user_question = st.text_area("Ask your question from the document")
28
+
29
+ if st.button("Answer"):
30
+ answer = answer_question(user_question)
31
+ answer_deepseek = answer["answer_deepseek"]
32
+ answer_llama3 = answer["answer_llama3"]
33
+
34
+ col1, col2 = st.columns(2)
35
+
36
+ with col1:
37
+ st.markdown("### DeepSeek-r1 Response")
38
+ st.markdown(
39
+ f"""
40
+ <div style="border: 1px solid #ccc; padding: 10px; border-radius: 5px; background-color: #f9f9f9;">
41
+ {answer_deepseek}
42
+ </div>
43
+ """,
44
+ unsafe_allow_html=True
45
+ )
46
+
47
+ with col2:
48
+ st.markdown("### Llama-3 Response")
49
+ st.markdown(
50
+ f"""
51
+ <div style="border: 1px solid #ccc; padding: 10px; border-radius: 5px; background-color: #f9f9f9;">
52
+ {answer_llama3}
53
+ </div>
54
+ """,
55
+ unsafe_allow_html=True
56
+ )