Spaces:
Running
Running
Upload app.py
Browse files
app.py
CHANGED
@@ -78,27 +78,7 @@ Follow this example structure, MUST be in {language} language:
|
|
78 |
)
|
79 |
try:
|
80 |
podcast_match = re.search(r'{(.*?)}', response.choices[0].message.content, re.DOTALL)
|
81 |
-
|
82 |
-
podcast_dict = json.loads(podcast_match)
|
83 |
-
|
84 |
-
podcast_json = {
|
85 |
-
"topic": "AGI",
|
86 |
-
"podcast": []
|
87 |
-
}
|
88 |
-
|
89 |
-
speaker_map = {"speaker1": 1, "speaker2": 2}
|
90 |
-
|
91 |
-
for speaker, line in podcast_dict.items():
|
92 |
-
podcast_json["podcast"].append({
|
93 |
-
"speaker": speaker_map[speaker],
|
94 |
-
"line": line
|
95 |
-
})
|
96 |
-
|
97 |
-
return json.dumps(podcast_json, ensure_ascii=False, indent=2)
|
98 |
-
else:
|
99 |
-
raise gr.Error("Failed to generate podcast script. Please try again.")
|
100 |
-
except json.JSONDecodeError:
|
101 |
-
raise gr.Error("Invalid JSON format in the generated response. Please try again.")
|
102 |
except Exception as e:
|
103 |
if "API key not valid" in str(e):
|
104 |
raise gr.Error("Invalid API key. Please provide a valid API key.")
|
@@ -106,6 +86,7 @@ Follow this example structure, MUST be in {language} language:
|
|
106 |
raise gr.Error("Rate limit exceeded for the API key. Please try again later or provide your own API key.")
|
107 |
else:
|
108 |
raise gr.Error(f"Failed to generate podcast script: {e}")
|
|
|
109 |
|
110 |
with gr.Blocks() as iface:
|
111 |
gr.Markdown("# 🎙️ Generated Podcast Audio. Deployed by 江信宗")
|
|
|
78 |
)
|
79 |
try:
|
80 |
podcast_match = re.search(r'{(.*?)}', response.choices[0].message.content, re.DOTALL)
|
81 |
+
print(response.choices[0].message.content)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
82 |
except Exception as e:
|
83 |
if "API key not valid" in str(e):
|
84 |
raise gr.Error("Invalid API key. Please provide a valid API key.")
|
|
|
86 |
raise gr.Error("Rate limit exceeded for the API key. Please try again later or provide your own API key.")
|
87 |
else:
|
88 |
raise gr.Error(f"Failed to generate podcast script: {e}")
|
89 |
+
return podcast_match.group(0)
|
90 |
|
91 |
with gr.Blocks() as iface:
|
92 |
gr.Markdown("# 🎙️ Generated Podcast Audio. Deployed by 江信宗")
|