Update app.py
Browse files
app.py
CHANGED
@@ -3,10 +3,11 @@ import openai
|
|
3 |
import fitz # PyMuPDF
|
4 |
import numpy as np
|
5 |
from sklearn.metrics.pairwise import cosine_similarity
|
|
|
6 |
|
7 |
-
# Function to extract text from the PDF file
|
8 |
-
def extract_pdf_text(
|
9 |
-
doc = fitz.open(
|
10 |
text = ""
|
11 |
for page in doc:
|
12 |
text += page.get_text("text")
|
@@ -41,7 +42,7 @@ def get_relevant_context(pdf_text, query, num_contexts=3):
|
|
41 |
def generate_response(context, question):
|
42 |
prompt = f"The following is an excerpt from a research paper on GPT-4. Please answer the question based on this context:\n\nContext: {context}\n\nQuestion: {question}\nAnswer:"
|
43 |
response = openai.Completion.create(
|
44 |
-
model="gpt-
|
45 |
prompt=prompt,
|
46 |
max_tokens=200,
|
47 |
temperature=0.7,
|
|
|
3 |
import fitz # PyMuPDF
|
4 |
import numpy as np
|
5 |
from sklearn.metrics.pairwise import cosine_similarity
|
6 |
+
from io import BytesIO
|
7 |
|
8 |
+
# Function to extract text from the uploaded PDF file
|
9 |
+
def extract_pdf_text(pdf_file):
|
10 |
+
doc = fitz.open(stream=pdf_file.read(), filetype="pdf")
|
11 |
text = ""
|
12 |
for page in doc:
|
13 |
text += page.get_text("text")
|
|
|
42 |
def generate_response(context, question):
|
43 |
prompt = f"The following is an excerpt from a research paper on GPT-4. Please answer the question based on this context:\n\nContext: {context}\n\nQuestion: {question}\nAnswer:"
|
44 |
response = openai.Completion.create(
|
45 |
+
model="gpt-4-0314", # Replace with the appropriate model identifier
|
46 |
prompt=prompt,
|
47 |
max_tokens=200,
|
48 |
temperature=0.7,
|