Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -171,37 +171,6 @@ def generate_speech(text, voice1, voice2, temperature, top_p, repetition_penalty
|
|
171 |
return None
|
172 |
|
173 |
try:
|
174 |
-
genai.configure(api_key=api_key)
|
175 |
-
model = genai.GenerativeModel('gemini-2.5-pro-preview-03-25')
|
176 |
-
|
177 |
-
combined_content = prompt or ""
|
178 |
-
|
179 |
-
if uploaded_file is not None:
|
180 |
-
file_bytes = io.BytesIO(uploaded_file)
|
181 |
-
|
182 |
-
# Try to detect the file type based on content
|
183 |
-
file_bytes.seek(0)
|
184 |
-
if file_bytes.read(4) == b'%PDF':
|
185 |
-
# It's a PDF file
|
186 |
-
file_bytes.seek(0)
|
187 |
-
pdf_reader = PyPDF2.PdfReader(file_bytes)
|
188 |
-
file_content = "\n".join([page.extract_text() for page in pdf_reader.pages])
|
189 |
-
else:
|
190 |
-
# Try as text file first
|
191 |
-
file_bytes.seek(0)
|
192 |
-
try:
|
193 |
-
file_content = file_bytes.read().decode('utf-8')
|
194 |
-
except UnicodeDecodeError:
|
195 |
-
# If it's not a text file, try as a docx
|
196 |
-
file_bytes.seek(0)
|
197 |
-
try:
|
198 |
-
doc = Document(file_bytes)
|
199 |
-
file_content = "\n".join([para.text for para in doc.paragraphs])
|
200 |
-
except:
|
201 |
-
raise ValueError("Unsupported file type or corrupted file")
|
202 |
-
|
203 |
-
combined_content += "\n" + file_content if combined_content else file_content
|
204 |
-
|
205 |
progress(0.1, "Processing text...")
|
206 |
paragraphs = text.split('\n\n') # Split by double newline
|
207 |
audio_samples = []
|
@@ -265,7 +234,8 @@ with gr.Blocks(title="Orpheus Text-to-Speech") as demo:
|
|
265 |
interactive=True,
|
266 |
container=True
|
267 |
)
|
268 |
-
|
|
|
269 |
with gr.Column(scale=2):
|
270 |
duration = gr.Slider(minimum=1, maximum=60, value=5, step=1, label="Duration (minutes)")
|
271 |
num_hosts = gr.Radio(["1", "2"], label="Number of Hosts", value="1")
|
|
|
171 |
return None
|
172 |
|
173 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
174 |
progress(0.1, "Processing text...")
|
175 |
paragraphs = text.split('\n\n') # Split by double newline
|
176 |
audio_samples = []
|
|
|
234 |
interactive=True,
|
235 |
container=True
|
236 |
)
|
237 |
+
uploaded_file = gr.File(label="Upload File", type=["txt", "docx", "pdf"])
|
238 |
+
|
239 |
with gr.Column(scale=2):
|
240 |
duration = gr.Slider(minimum=1, maximum=60, value=5, step=1, label="Duration (minutes)")
|
241 |
num_hosts = gr.Radio(["1", "2"], label="Number of Hosts", value="1")
|