Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -40,6 +40,32 @@ def generate_podcast_script(api_key, prompt, uploaded_file, duration, num_hosts)
|
|
40 |
model = genai.GenerativeModel('gemini-2.5-pro-preview-03-25')
|
41 |
|
42 |
combined_content = prompt or ""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
43 |
|
44 |
if uploaded_file is not None:
|
45 |
# Handle the uploaded file content
|
|
|
40 |
model = genai.GenerativeModel('gemini-2.5-pro-preview-03-25')
|
41 |
|
42 |
combined_content = prompt or ""
|
43 |
+
|
44 |
+
if uploaded_file is not None:
|
45 |
+
file_bytes = io.BytesIO(uploaded_file)
|
46 |
+
|
47 |
+
# Try to detect the file type based on content
|
48 |
+
file_bytes.seek(0)
|
49 |
+
if file_bytes.read(4) == b'%PDF':
|
50 |
+
# It's a PDF file
|
51 |
+
file_bytes.seek(0)
|
52 |
+
pdf_reader = PyPDF2.PdfReader(file_bytes)
|
53 |
+
file_content = "\n".join([page.extract_text() for page in pdf_reader.pages])
|
54 |
+
else:
|
55 |
+
# Try as text file first
|
56 |
+
file_bytes.seek(0)
|
57 |
+
try:
|
58 |
+
file_content = file_bytes.read().decode('utf-8')
|
59 |
+
except UnicodeDecodeError:
|
60 |
+
# If it's not a text file, try as a docx
|
61 |
+
file_bytes.seek(0)
|
62 |
+
try:
|
63 |
+
doc = Document(file_bytes)
|
64 |
+
file_content = "\n".join([para.text for para in doc.paragraphs])
|
65 |
+
except:
|
66 |
+
raise ValueError("Unsupported file type or corrupted file")
|
67 |
+
|
68 |
+
combined_content += "\n" + file_content if combined_content else file_content</code></pre></div></pre>
|
69 |
|
70 |
if uploaded_file is not None:
|
71 |
# Handle the uploaded file content
|