Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -32,7 +32,7 @@ def create_persona(text):
|
|
32 |
model="gpt-3.5-turbo",
|
33 |
messages=[
|
34 |
{"role": "system", "content": "You are a knowledgeable assistant."},
|
35 |
-
{"role": "user", "content": text},
|
36 |
]
|
37 |
)
|
38 |
return response['choices'][0]['message']['content']
|
@@ -64,21 +64,20 @@ def call_openai_api(persona, user_prompt):
|
|
64 |
|
65 |
def pdf_to_text(file, user_prompt):
|
66 |
z = zipfile.ZipFile(file.name, 'r')
|
67 |
-
|
68 |
for filename in z.namelist():
|
69 |
if filename.endswith('.pdf'):
|
70 |
pdf_file_data = z.read(filename)
|
71 |
pdf_file_io = io.BytesIO(pdf_file_data)
|
72 |
pdf = PdfReader(pdf_file_io)
|
73 |
-
text = ''
|
74 |
for page in pdf.pages:
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
|
83 |
iface = gr.Interface(
|
84 |
fn=pdf_to_text,
|
|
|
32 |
model="gpt-3.5-turbo",
|
33 |
messages=[
|
34 |
{"role": "system", "content": "You are a knowledgeable assistant."},
|
35 |
+
{"role": "user", "content": f"Create a persona based on this text: {text}"},
|
36 |
]
|
37 |
)
|
38 |
return response['choices'][0]['message']['content']
|
|
|
64 |
|
65 |
def pdf_to_text(file, user_prompt):
|
66 |
z = zipfile.ZipFile(file.name, 'r')
|
67 |
+
aggregated_text = ''
|
68 |
for filename in z.namelist():
|
69 |
if filename.endswith('.pdf'):
|
70 |
pdf_file_data = z.read(filename)
|
71 |
pdf_file_io = io.BytesIO(pdf_file_data)
|
72 |
pdf = PdfReader(pdf_file_io)
|
|
|
73 |
for page in pdf.pages:
|
74 |
+
aggregated_text += page.extract_text()
|
75 |
+
# Create a single persona from all text
|
76 |
+
persona = create_persona(aggregated_text)
|
77 |
+
# Using OpenAI API
|
78 |
+
response = call_openai_api(persona, user_prompt)
|
79 |
+
return response
|
80 |
+
|
81 |
|
82 |
iface = gr.Interface(
|
83 |
fn=pdf_to_text,
|