shukdevdatta123 commited on
Commit
17b3855
·
verified ·
1 Parent(s): b1b13f6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -4
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(pdf_file_path):
9
- doc = fitz.open(pdf_file_path)
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-4o-mini", # Replace with the appropriate model identifier
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,