Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -2,7 +2,7 @@ import gradio as gr
|
|
2 |
import fitz # PyMuPDF
|
3 |
import torch
|
4 |
from transformers import AutoTokenizer, AutoModelForCausalLM
|
5 |
-
from
|
6 |
from langchain_community.embeddings import HuggingFaceEmbeddings
|
7 |
from langchain_text_splitters import RecursiveCharacterTextSplitter
|
8 |
import os
|
@@ -33,9 +33,9 @@ def get_llm_response(input_prompt, content, prompt):
|
|
33 |
|
34 |
|
35 |
# Function to extract text from PDF file
|
36 |
-
def extract_text_from_pdf(
|
37 |
try:
|
38 |
-
doc = fitz.open(
|
39 |
text = ""
|
40 |
for page in doc:
|
41 |
text += page.get_text()
|
@@ -47,7 +47,7 @@ def extract_text_from_pdf(file):
|
|
47 |
def process_pdf(uploaded_file, prompt):
|
48 |
if uploaded_file is not None:
|
49 |
# Extract text from uploaded PDF file
|
50 |
-
pdf_text = extract_text_from_pdf(uploaded_file)
|
51 |
if pdf_text:
|
52 |
try:
|
53 |
# Create embeddings
|
@@ -92,8 +92,8 @@ def process_pdf(uploaded_file, prompt):
|
|
92 |
def main():
|
93 |
gr.Interface(
|
94 |
fn=process_pdf,
|
95 |
-
inputs=[gr.
|
96 |
-
gr.
|
97 |
outputs="text",
|
98 |
title="PDF Chatbot",
|
99 |
description="Upload a PDF file and ask questions about its content."
|
|
|
2 |
import fitz # PyMuPDF
|
3 |
import torch
|
4 |
from transformers import AutoTokenizer, AutoModelForCausalLM
|
5 |
+
from langchain_community.vectorstores import Chroma
|
6 |
from langchain_community.embeddings import HuggingFaceEmbeddings
|
7 |
from langchain_text_splitters import RecursiveCharacterTextSplitter
|
8 |
import os
|
|
|
33 |
|
34 |
|
35 |
# Function to extract text from PDF file
|
36 |
+
def extract_text_from_pdf(file_path):
|
37 |
try:
|
38 |
+
doc = fitz.open(file_path)
|
39 |
text = ""
|
40 |
for page in doc:
|
41 |
text += page.get_text()
|
|
|
47 |
def process_pdf(uploaded_file, prompt):
|
48 |
if uploaded_file is not None:
|
49 |
# Extract text from uploaded PDF file
|
50 |
+
pdf_text = extract_text_from_pdf(uploaded_file.name)
|
51 |
if pdf_text:
|
52 |
try:
|
53 |
# Create embeddings
|
|
|
92 |
def main():
|
93 |
gr.Interface(
|
94 |
fn=process_pdf,
|
95 |
+
inputs=[gr.File(type="filepath", label="Upload PDF File"),
|
96 |
+
gr.Textbox(lines=2, placeholder="Ask a Question")],
|
97 |
outputs="text",
|
98 |
title="PDF Chatbot",
|
99 |
description="Upload a PDF file and ask questions about its content."
|