fix: /app dire permission issues
Browse files- gradio_app.py +14 -14
gradio_app.py
CHANGED
@@ -96,42 +96,42 @@ def process_pdf(pdf_file, speaker1_voice, speaker2_voice, provider, api_key, ope
|
|
96 |
else:
|
97 |
os.environ["OPENROUTER_API_BASE"] = openrouter_base or "https://openrouter.ai/api/v1"
|
98 |
|
|
|
99 |
if pdf_file is None:
|
100 |
return "No file uploaded", None
|
101 |
|
102 |
-
# Use /tmp
|
103 |
-
base_dir = "/tmp" if os.
|
104 |
|
105 |
-
#
|
106 |
-
|
107 |
-
tmp_path = os.path.join(base_dir, f"uploaded_{pdf_filename}")
|
108 |
shutil.copy2(pdf_file.name, tmp_path)
|
109 |
print(f"[INFO] Uploaded PDF saved at {tmp_path}")
|
110 |
|
111 |
-
# Generate
|
112 |
transcript, transcript_path = generate_podcast_script(tmp_path, provider=provider)
|
113 |
if transcript is None:
|
114 |
return "Error generating transcript", None
|
115 |
|
116 |
-
# Define
|
117 |
audio_output_path = os.path.join(
|
118 |
-
|
119 |
-
f"audio_{os.path.
|
120 |
)
|
121 |
|
122 |
-
#
|
123 |
with concurrent.futures.ProcessPoolExecutor(max_workers=NUM_WORKERS) as executor:
|
124 |
-
print(f"[INFO] Processing with {NUM_WORKERS} CPU cores")
|
125 |
future = executor.submit(
|
126 |
generate_audio_from_script_with_voices,
|
127 |
transcript, speaker1_voice, speaker2_voice, audio_output_path
|
128 |
)
|
129 |
result = future.result()
|
130 |
|
131 |
-
|
132 |
-
|
133 |
|
134 |
-
|
135 |
|
136 |
except Exception as e:
|
137 |
print(f"[ERROR] process_pdf failed: {str(e)}")
|
|
|
96 |
else:
|
97 |
os.environ["OPENROUTER_API_BASE"] = openrouter_base or "https://openrouter.ai/api/v1"
|
98 |
|
99 |
+
# Check if file is uploaded
|
100 |
if pdf_file is None:
|
101 |
return "No file uploaded", None
|
102 |
|
103 |
+
# Use /tmp if writable, else fallback to current directory
|
104 |
+
base_dir = "/tmp" if os.access("/tmp", os.W_OK) else os.getcwd()
|
105 |
|
106 |
+
# Save uploaded PDF to temp location
|
107 |
+
tmp_path = os.path.join(base_dir, f"uploaded_{os.path.basename(pdf_file.name)}")
|
|
|
108 |
shutil.copy2(pdf_file.name, tmp_path)
|
109 |
print(f"[INFO] Uploaded PDF saved at {tmp_path}")
|
110 |
|
111 |
+
# Generate podcast script
|
112 |
transcript, transcript_path = generate_podcast_script(tmp_path, provider=provider)
|
113 |
if transcript is None:
|
114 |
return "Error generating transcript", None
|
115 |
|
116 |
+
# Define output file path
|
117 |
audio_output_path = os.path.join(
|
118 |
+
os.path.dirname(tmp_path),
|
119 |
+
f"audio_{os.path.basename(tmp_path).replace('.pdf', '.wav')}"
|
120 |
)
|
121 |
|
122 |
+
# Generate audio using ProcessPoolExecutor
|
123 |
with concurrent.futures.ProcessPoolExecutor(max_workers=NUM_WORKERS) as executor:
|
124 |
+
print(f"[INFO] Processing audio with {NUM_WORKERS} CPU cores")
|
125 |
future = executor.submit(
|
126 |
generate_audio_from_script_with_voices,
|
127 |
transcript, speaker1_voice, speaker2_voice, audio_output_path
|
128 |
)
|
129 |
result = future.result()
|
130 |
|
131 |
+
if result is None:
|
132 |
+
return "Error generating audio", None
|
133 |
|
134 |
+
return "Process complete!", result
|
135 |
|
136 |
except Exception as e:
|
137 |
print(f"[ERROR] process_pdf failed: {str(e)}")
|