Update app.py
Browse files
app.py
CHANGED
|
@@ -5,14 +5,14 @@ import numpy as np
|
|
| 5 |
from transformers import pipeline
|
| 6 |
import requests
|
| 7 |
|
| 8 |
-
# Initialize the summarization
|
| 9 |
summarizer = pipeline("summarization")
|
|
|
|
| 10 |
|
| 11 |
# Groq API Configuration
|
| 12 |
API_KEY = "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" # Replace with your actual Groq API key
|
| 13 |
API_URL = "https://api.groq.com/openai/v1/chat/completions" # Default endpoint for chat completions (check Groq docs)
|
| 14 |
|
| 15 |
-
|
| 16 |
# PDF Processing Function
|
| 17 |
def extract_text_from_pdf(pdf_file):
|
| 18 |
# Read the file from the uploaded BytesIO object
|
|
@@ -60,7 +60,7 @@ def call_groq_api(input_text):
|
|
| 60 |
return f"Error: {str(e)}"
|
| 61 |
|
| 62 |
# Streamlit UI
|
| 63 |
-
st.title("RAG-based PDF Summarizer")
|
| 64 |
|
| 65 |
# Upload PDF file
|
| 66 |
pdf_file = st.file_uploader("Upload a PDF file", type="pdf")
|
|
@@ -82,7 +82,12 @@ if pdf_file:
|
|
| 82 |
relevant_chunk = retrieve_relevant_chunk(query, index, sentences)
|
| 83 |
st.write(f"Relevant Text: {relevant_chunk}")
|
| 84 |
|
| 85 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 86 |
st.write("Summarizing...")
|
| 87 |
summary = summarizer(relevant_chunk, max_length=150, min_length=50, do_sample=False)[0]['summary_text']
|
| 88 |
st.write(f"Summary: {summary}")
|
|
|
|
| 5 |
from transformers import pipeline
|
| 6 |
import requests
|
| 7 |
|
| 8 |
+
# Initialize the summarization and question-answering models from Hugging Face
|
| 9 |
summarizer = pipeline("summarization")
|
| 10 |
+
qa_pipeline = pipeline("question-answering") # Adding the question-answering pipeline
|
| 11 |
|
| 12 |
# Groq API Configuration
|
| 13 |
API_KEY = "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" # Replace with your actual Groq API key
|
| 14 |
API_URL = "https://api.groq.com/openai/v1/chat/completions" # Default endpoint for chat completions (check Groq docs)
|
| 15 |
|
|
|
|
| 16 |
# PDF Processing Function
|
| 17 |
def extract_text_from_pdf(pdf_file):
|
| 18 |
# Read the file from the uploaded BytesIO object
|
|
|
|
| 60 |
return f"Error: {str(e)}"
|
| 61 |
|
| 62 |
# Streamlit UI
|
| 63 |
+
st.title("RAG-based PDF Summarizer and Q&A")
|
| 64 |
|
| 65 |
# Upload PDF file
|
| 66 |
pdf_file = st.file_uploader("Upload a PDF file", type="pdf")
|
|
|
|
| 82 |
relevant_chunk = retrieve_relevant_chunk(query, index, sentences)
|
| 83 |
st.write(f"Relevant Text: {relevant_chunk}")
|
| 84 |
|
| 85 |
+
# Answer the question based on the relevant chunk
|
| 86 |
+
st.write("Answering the question...")
|
| 87 |
+
answer = qa_pipeline(question=query, context=relevant_chunk) # Use question-answering pipeline
|
| 88 |
+
st.write(f"Answer: {answer['answer']}")
|
| 89 |
+
|
| 90 |
+
# Optionally, summarize the relevant chunk
|
| 91 |
st.write("Summarizing...")
|
| 92 |
summary = summarizer(relevant_chunk, max_length=150, min_length=50, do_sample=False)[0]['summary_text']
|
| 93 |
st.write(f"Summary: {summary}")
|