Spaces:
Runtime error
Runtime error
| import os | |
| import gradio as gr | |
| from rag_utility import process_document_to_chromadb, answer_question | |
| def process_and_store_file(file): | |
| if file is not None: | |
| working_dir = os.getcwd() | |
| save_path = os.path.join(working_dir, os.path.basename(file)) | |
| with open(save_path, "wb") as f: | |
| f.write(file.read()) | |
| process_document_to_chromadb(save_path) | |
| return "Document Processed Successfully" | |
| return "No file uploaded." | |
| def get_answers(question): | |
| if not question.strip(): | |
| return "Please enter a question.", "Please enter a question." | |
| answer = answer_question(question) | |
| return answer["answer_deepseek"], answer["answer_llama3"] | |
| with gr.Blocks() as demo: | |
| gr.Markdown("# π DeepSeek-R1 vs π¦ Llama-3") | |
| with gr.Row(): | |
| file_input = gr.File(label="Upload a PDF file", file_types=[".pdf"], type="filepath") | |
| process_button = gr.Button("Process Document") | |
| status_output = gr.Textbox(label="Status", interactive=False) | |
| process_button.click(process_and_store_file, inputs=file_input, outputs=status_output) | |
| question_input = gr.Textbox(label="Ask your question from the document") | |
| answer_button = gr.Button("Answer") | |
| with gr.Row(): | |
| deepseek_output = gr.Markdown("### DeepSeek-r1 Response") | |
| llama3_output = gr.Markdown("### Llama-3 Response") | |
| answer_button.click(get_answers, inputs=question_input, outputs=[deepseek_output, llama3_output]) | |
| demo.launch() | |