Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,57 +1,3 @@
|
|
| 1 |
-
# import gradio as gr
|
| 2 |
-
# import fitz # PyMuPDF
|
| 3 |
-
# from langchain.text_splitter import RecursiveCharacterTextSplitter
|
| 4 |
-
# from langchain.schema import Document
|
| 5 |
-
# from langchain_community.vectorstores import Chroma
|
| 6 |
-
# from langchain.embeddings import OpenAIEmbeddings
|
| 7 |
-
# from langchain.llms import OpenAI
|
| 8 |
-
# from langchain.prompts import PromptTemplate
|
| 9 |
-
# from langchain.memory import ConversationBufferMemory
|
| 10 |
-
# from langchain.chains import ConversationalRetrievalChain
|
| 11 |
-
# import os
|
| 12 |
-
|
| 13 |
-
# def extract_text_from_pdf(pdf_path):
|
| 14 |
-
# doc = fitz.open(pdf_path)
|
| 15 |
-
# text = ""
|
| 16 |
-
# for page_num in range(len(doc)):
|
| 17 |
-
# page = doc.load_page(page_num)
|
| 18 |
-
# text += page.get_text()
|
| 19 |
-
# return text
|
| 20 |
-
|
| 21 |
-
# # Load the text from the PDF and preprocess
|
| 22 |
-
# openai_api_key = os.getenv("OPENAI_API_KEY")
|
| 23 |
-
# pdf_path = "iess402.pdf" # Path to your PDF file
|
| 24 |
-
# pdf_text = extract_text_from_pdf(pdf_path)
|
| 25 |
-
# document = Document(page_content=pdf_text, metadata={})
|
| 26 |
-
# text_splitter = RecursiveCharacterTextSplitter(chunk_size=500, chunk_overlap=25)
|
| 27 |
-
# all_splits = text_splitter.split_documents([document])
|
| 28 |
-
|
| 29 |
-
# # Create vector store and setup the QA chain
|
| 30 |
-
# vectorstore = Chroma.from_documents(documents=all_splits, embedding=OpenAIEmbeddings(api_key=openai_api_key))
|
| 31 |
-
# llm = OpenAI(api_key=openai_api_key, temperature=0, model="gpt-3.5-turbo-instruct", verbose=True)
|
| 32 |
-
# template = """Use the following pieces of context to answer the question at the end. If you don't know the answer, just say that you don't know, don't try to make up an answer. Keep the answer as concise as possible. Always say "thanks for asking!" at the end of the answer.
|
| 33 |
-
# {context}
|
| 34 |
-
# Question: {question}
|
| 35 |
-
# Helpful Answer:"""
|
| 36 |
-
# QA_CHAIN_PROMPT = PromptTemplate(input_variables=["context", "question"], template=template)
|
| 37 |
-
|
| 38 |
-
# # Setup conversational retrieval chain with memory
|
| 39 |
-
# memory = ConversationBufferMemory(memory_key="chat_history", return_messages=True)
|
| 40 |
-
# retriever = vectorstore.as_retriever()
|
| 41 |
-
# qa = ConversationalRetrievalChain.from_llm(llm, retriever=retriever, memory=memory)
|
| 42 |
-
|
| 43 |
-
# # Define the function to ask questions and get answers
|
| 44 |
-
# def ask_question(question):
|
| 45 |
-
# result = qa.invoke({"question": question})
|
| 46 |
-
# return result['answer']
|
| 47 |
-
|
| 48 |
-
# # Create the Gradio interface
|
| 49 |
-
# iface = gr.Interface(fn=ask_question, inputs="text", outputs="text", title="PDF QA System", description="Ask questions based Textbook in Political Science for Class IX chapter 2.")
|
| 50 |
-
|
| 51 |
-
# # Launch the Gradio interface
|
| 52 |
-
# iface.launch()
|
| 53 |
-
|
| 54 |
-
|
| 55 |
import gradio as gr
|
| 56 |
import fitz # PyMuPDF
|
| 57 |
import re
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import fitz # PyMuPDF
|
| 3 |
import re
|