Spaces:
Runtime error
Runtime error
Commit
·
7dbfbec
1
Parent(s):
c99f1a1
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,3 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import os
|
| 3 |
import tempfile
|
|
@@ -12,21 +51,12 @@ from langchain import HuggingFaceHub
|
|
| 12 |
|
| 13 |
# Set your API keys
|
| 14 |
API_KEY = os.environ["API_KEY"]
|
| 15 |
-
pdf_path = './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 |
-
|
| 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,11 +87,27 @@ chat_interface = gr.ChatInterface(
|
|
| 57 |
|
| 58 |
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
| 59 |
with gr.Row():
|
| 60 |
-
with gr.Column():
|
| 61 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
chat_interface = gr.ChatInterface(
|
| 63 |
chat,
|
| 64 |
theme=gr.themes.Soft()
|
| 65 |
)
|
| 66 |
|
| 67 |
demo.queue().launch(inline=False)
|
|
|
|
|
|
| 1 |
+
Hugging Face's logo
|
| 2 |
+
Hugging Face
|
| 3 |
+
Search models, datasets, users...
|
| 4 |
+
Models
|
| 5 |
+
Datasets
|
| 6 |
+
Spaces
|
| 7 |
+
Docs
|
| 8 |
+
Solutions
|
| 9 |
+
Pricing
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
Hugging Face is way more fun with friends and colleagues! 🤗 Join an organization
|
| 14 |
+
Spaces:
|
| 15 |
+
|
| 16 |
+
salemamassi
|
| 17 |
+
/
|
| 18 |
+
GeneralPdfChatBot
|
| 19 |
+
|
| 20 |
+
private
|
| 21 |
+
|
| 22 |
+
Logs
|
| 23 |
+
App
|
| 24 |
+
Files
|
| 25 |
+
Community
|
| 26 |
+
Settings
|
| 27 |
+
GeneralPdfChatBot
|
| 28 |
+
/
|
| 29 |
+
app.py
|
| 30 |
+
salemamassi's picture
|
| 31 |
+
salemamassi
|
| 32 |
+
Update app.py
|
| 33 |
+
133e845
|
| 34 |
+
1 day ago
|
| 35 |
+
raw
|
| 36 |
+
history
|
| 37 |
+
blame
|
| 38 |
+
No virus
|
| 39 |
+
2.83 kB
|
| 40 |
import gradio as gr
|
| 41 |
import os
|
| 42 |
import tempfile
|
|
|
|
| 51 |
|
| 52 |
# Set your API keys
|
| 53 |
API_KEY = os.environ["API_KEY"]
|
|
|
|
| 54 |
|
| 55 |
# Create a temporary upload directory
|
| 56 |
|
| 57 |
# Define global variables for loaders and index
|
| 58 |
index = None
|
| 59 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
|
| 61 |
def chat(message,history):
|
| 62 |
global index
|
|
|
|
| 87 |
|
| 88 |
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
| 89 |
with gr.Row():
|
| 90 |
+
with gr.Column(scale=1):
|
| 91 |
+
with gr.Row():
|
| 92 |
+
upload_file = gr.File(label="Upload a PDF",file_types=["pdf"])
|
| 93 |
+
with gr.Row():
|
| 94 |
+
upload_button = gr.Button(label="Upload a PDF")
|
| 95 |
+
with gr.Row():
|
| 96 |
+
text = gr.Textbox(label="Status")
|
| 97 |
+
def load_file(pdf_file):
|
| 98 |
+
global index
|
| 99 |
+
pdf_loader = UnstructuredPDFLoader(pdf_file.name)
|
| 100 |
+
index = VectorstoreIndexCreator(
|
| 101 |
+
embedding=HuggingFaceEmbeddings(),
|
| 102 |
+
text_splitter=CharacterTextSplitter(chunk_size=1000, chunk_overlap=0)
|
| 103 |
+
).from_loaders([pdf_loader])
|
| 104 |
+
return "DONE ✅"
|
| 105 |
+
upload_button.click(load_file, [upload_file], text)
|
| 106 |
+
with gr.Column(scale=2):
|
| 107 |
chat_interface = gr.ChatInterface(
|
| 108 |
chat,
|
| 109 |
theme=gr.themes.Soft()
|
| 110 |
)
|
| 111 |
|
| 112 |
demo.queue().launch(inline=False)
|
| 113 |
+
|