salemamassi commited on
Commit
424b8b6
·
1 Parent(s): 766cd88

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -18
app.py CHANGED
@@ -12,12 +12,21 @@ from langchain import HuggingFaceHub
12
 
13
  # Set your API keys
14
  API_KEY = os.environ["API_KEY"]
 
15
 
16
  # Create a temporary upload directory
17
 
18
  # Define global variables for loaders and index
19
  index = None
20
-
 
 
 
 
 
 
 
 
21
 
22
  def chat(message,history):
23
  global index
@@ -48,23 +57,8 @@ chat_interface = gr.ChatInterface(
48
 
49
  with gr.Blocks(theme=gr.themes.Soft()) as demo:
50
  with gr.Row():
51
- with gr.Column(scale=1):
52
- with gr.Row():
53
- upload_file = gr.File(label="Upload a PDF",file_types=["pdf"])
54
- with gr.Row():
55
- upload_button = gr.Button(label="Upload a PDF")
56
- with gr.Row():
57
- text = gr.Textbox(label="Status")
58
- def load_file(pdf_file):
59
- global index
60
- pdf_loader = UnstructuredPDFLoader(pdf_file.name)
61
- index = VectorstoreIndexCreator(
62
- embedding=HuggingFaceEmbeddings(),
63
- text_splitter=CharacterTextSplitter(chunk_size=1000, chunk_overlap=0)
64
- ).from_loaders([pdf_loader])
65
- return "DONE ✅"
66
- upload_button.click(load_file, [upload_file], text)
67
- with gr.Column(scale=2):
68
  chat_interface = gr.ChatInterface(
69
  chat,
70
  theme=gr.themes.Soft()
 
12
 
13
  # Set your API keys
14
  API_KEY = os.environ["API_KEY"]
15
+ pdf_path = '/home/user/Adventure Works Analysis Report.pdf'
16
 
17
  # Create a temporary upload directory
18
 
19
  # Define global variables for loaders and index
20
  index = None
21
+ def load_file(pdf_path):
22
+ global index
23
+ pdf_loader = UnstructuredPDFLoader(pdf_path)
24
+ index = VectorstoreIndexCreator(
25
+ embedding=HuggingFaceEmbeddings(),
26
+ text_splitter=CharacterTextSplitter(chunk_size=1000, chunk_overlap=0)
27
+ ).from_loaders([pdf_loader])
28
+ return "DONE ✅"
29
+ load_file(pdf_path)
30
 
31
  def chat(message,history):
32
  global index
 
57
 
58
  with gr.Blocks(theme=gr.themes.Soft()) as demo:
59
  with gr.Row():
60
+ with gr.Column():
61
+ # text = gr.Textbox(load_file, [pdf_path],label="Status")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
62
  chat_interface = gr.ChatInterface(
63
  chat,
64
  theme=gr.themes.Soft()