Spaces:
Sleeping
Sleeping
yunfengcheng
commited on
Commit
·
4f65fc5
1
Parent(s):
850ae9a
Add application file
Browse files
app.py
ADDED
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import torch
|
2 |
+
|
3 |
+
# Check if a GPU is available
|
4 |
+
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
5 |
+
print(f"Using device: {device}")
|
6 |
+
|
7 |
+
import gradio as gr
|
8 |
+
|
9 |
+
# You can use this section to suppress warnings generated by your code:
|
10 |
+
def warn(*args, **kwargs):
|
11 |
+
pass
|
12 |
+
import warnings
|
13 |
+
warnings.warn = warn
|
14 |
+
warnings.filterwarnings('ignore')
|
15 |
+
|
16 |
+
def retriever_qa(file, query):
|
17 |
+
# llm = get_llm()
|
18 |
+
# retriever_obj = retriever(file)
|
19 |
+
# qa = RetrievalQA.from_chain_type(llm=llm,
|
20 |
+
# chain_type="stuff",
|
21 |
+
# retriever=retriever_obj,
|
22 |
+
# return_source_documents=False)
|
23 |
+
# response = qa.invoke(query)
|
24 |
+
with open(file, 'r') as f:
|
25 |
+
first_line = f.readline()
|
26 |
+
|
27 |
+
response = first_line + query
|
28 |
+
|
29 |
+
return response
|
30 |
+
|
31 |
+
rag_application = gr.Interface(
|
32 |
+
fn=retriever_qa,
|
33 |
+
allow_flagging="never",
|
34 |
+
inputs=[
|
35 |
+
# gr.File(label="Upload PDF File", file_count="single", file_types=['.pdf'], type="filepath"), # Drag and drop file upload
|
36 |
+
gr.File(label="Upload txt File", file_count="single", file_types=['.txt'], type="filepath"), # Drag and drop file upload
|
37 |
+
gr.Textbox(label="Input Query", lines=2, placeholder="Type your question here...")
|
38 |
+
],
|
39 |
+
outputs=gr.Textbox(label="Output"),
|
40 |
+
title="RAG Chatbot",
|
41 |
+
description="Upload a PDF document and ask any question. The chatbot will try to answer using the provided document."
|
42 |
+
)
|
43 |
+
|
44 |
+
rag_application.launch(share=True)
|