Spaces:
Runtime error
Runtime error
Update article_generator.py
Browse files- article_generator.py +8 -5
article_generator.py
CHANGED
|
@@ -147,7 +147,7 @@ def expand_section_with_gpt4(h2_text, h3_texts, preloaded_data):
|
|
| 147 |
temperature=0.7,
|
| 148 |
max_tokens=2000
|
| 149 |
)
|
| 150 |
-
expanded_text = response.choices[0]
|
| 151 |
expanded_texts.append(expanded_text)
|
| 152 |
except Exception as e:
|
| 153 |
error_message = f"Error in generating text for {prompt}: {str(e)}"
|
|
@@ -163,7 +163,7 @@ def generate_expanded_article(article_html):
|
|
| 163 |
preloaded_data = load_preloaded_tavily_data()
|
| 164 |
|
| 165 |
for h2 in h2_elements:
|
| 166 |
-
h3_texts = [h3.get_text() for h3 in h2.find_next_siblings('h3'
|
| 167 |
expanded_texts = expand_section_with_gpt4(h2.get_text(), h3_texts, preloaded_data)
|
| 168 |
|
| 169 |
for h3, expanded_text in zip(h3_texts, expanded_texts):
|
|
@@ -344,13 +344,16 @@ def continue_generate_article():
|
|
| 344 |
|
| 345 |
final_result = "\n".join(results)
|
| 346 |
|
|
|
|
|
|
|
|
|
|
| 347 |
with open("output3.txt", "w", encoding="utf-8") as f:
|
| 348 |
-
f.write(
|
| 349 |
|
| 350 |
-
print(
|
| 351 |
|
| 352 |
# ็ๆใๅฎไบใใใ็ถๆ
ใใกใคใซใๅ้ค
|
| 353 |
if os.path.exists("state.json"):
|
| 354 |
os.remove("state.json")
|
| 355 |
|
| 356 |
-
return
|
|
|
|
| 147 |
temperature=0.7,
|
| 148 |
max_tokens=2000
|
| 149 |
)
|
| 150 |
+
expanded_text = response.choices[0]["message"]["content"].strip()
|
| 151 |
expanded_texts.append(expanded_text)
|
| 152 |
except Exception as e:
|
| 153 |
error_message = f"Error in generating text for {prompt}: {str(e)}"
|
|
|
|
| 163 |
preloaded_data = load_preloaded_tavily_data()
|
| 164 |
|
| 165 |
for h2 in h2_elements:
|
| 166 |
+
h3_texts = [h3.get_text() for h3 in h2.find_next_siblings('h3')]
|
| 167 |
expanded_texts = expand_section_with_gpt4(h2.get_text(), h3_texts, preloaded_data)
|
| 168 |
|
| 169 |
for h3, expanded_text in zip(h3_texts, expanded_texts):
|
|
|
|
| 344 |
|
| 345 |
final_result = "\n".join(results)
|
| 346 |
|
| 347 |
+
# ็ๆใใใๅๆ่จไบใๆกๅผต
|
| 348 |
+
expanded_article = generate_expanded_article(final_result)
|
| 349 |
+
|
| 350 |
with open("output3.txt", "w", encoding="utf-8") as f:
|
| 351 |
+
f.write(expanded_article)
|
| 352 |
|
| 353 |
+
print(expanded_article) # ใญใฐใซๆ็ต็ตๆใๅบๅ
|
| 354 |
|
| 355 |
# ็ๆใๅฎไบใใใ็ถๆ
ใใกใคใซใๅ้ค
|
| 356 |
if os.path.exists("state.json"):
|
| 357 |
os.remove("state.json")
|
| 358 |
|
| 359 |
+
return expanded_article
|