Spaces:
Sleeping
Sleeping
PierreBrunelle
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -40,31 +40,6 @@ def create_prompt(top_k_list: list[dict], question: str) -> str:
|
|
40 |
QUESTION:
|
41 |
{question}'''
|
42 |
|
43 |
-
@pxt.udf(return_type=pxt.AudioType())
|
44 |
-
def generate_audio(script: str, voice: str, api_key: str):
|
45 |
-
"""Generate audio from text using OpenAI's API"""
|
46 |
-
if not script or not voice:
|
47 |
-
return None
|
48 |
-
|
49 |
-
try:
|
50 |
-
response = requests.post(
|
51 |
-
"https://api.openai.com/v1/audio/speech",
|
52 |
-
headers={"Authorization": f"Bearer {api_key}"},
|
53 |
-
json={"model": "tts-1", "input": script, "voice": voice}
|
54 |
-
)
|
55 |
-
|
56 |
-
if response.status_code == 200:
|
57 |
-
temp_dir = os.path.join(os.getcwd(), "temp")
|
58 |
-
os.makedirs(temp_dir, exist_ok=True)
|
59 |
-
temp_file = os.path.join(temp_dir, f"audio_{os.urandom(8).hex()}.mp3")
|
60 |
-
|
61 |
-
with open(temp_file, 'wb') as f:
|
62 |
-
f.write(response.content)
|
63 |
-
return temp_file
|
64 |
-
except Exception as e:
|
65 |
-
print(f"Error in audio synthesis: {e}")
|
66 |
-
return None
|
67 |
-
|
68 |
# Document Processing
|
69 |
class DocumentProcessor:
|
70 |
@staticmethod
|
|
|
40 |
QUESTION:
|
41 |
{question}'''
|
42 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
43 |
# Document Processing
|
44 |
class DocumentProcessor:
|
45 |
@staticmethod
|