Max attempts
Browse files
app.py
CHANGED
|
@@ -5,10 +5,14 @@ import json
|
|
| 5 |
import shutil
|
| 6 |
from pathlib import Path
|
| 7 |
import base64
|
| 8 |
-
|
| 9 |
from main import generate_paper_poster
|
| 10 |
|
| 11 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
def process_paper_to_poster(
|
| 13 |
pdf_file,
|
| 14 |
model_choice,
|
|
@@ -64,6 +68,11 @@ def process_paper_to_poster(
|
|
| 64 |
output="" # 不再使用
|
| 65 |
)
|
| 66 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
# 图片处理完毕,开始生成JSON
|
| 68 |
yield None, None, None, "🖼️ Image processing completed! Generating JSON structure..."
|
| 69 |
|
|
@@ -268,7 +277,7 @@ def create_interface():
|
|
| 268 |
- Generated Poster is recommended to be viewed in fullscreen mode or download the HTML file to view in browser
|
| 269 |
- Requires a valid OpenAI API key with sufficient balance
|
| 270 |
- Figure detection service URL is required for extracting images from PDFs
|
| 271 |
-
- Processing time depends on paper length and complexity (usually
|
| 272 |
- Ensure the model name is correct and supported by your API
|
| 273 |
- Download the HTML file and open it in your browser for the best viewing experience
|
| 274 |
|
|
|
|
| 5 |
import shutil
|
| 6 |
from pathlib import Path
|
| 7 |
import base64
|
| 8 |
+
import logging
|
| 9 |
from main import generate_paper_poster
|
| 10 |
|
| 11 |
|
| 12 |
+
logging.basicConfig(level=logging.DEBUG)
|
| 13 |
+
logger = logging.getLogger(__name__)
|
| 14 |
+
|
| 15 |
+
|
| 16 |
def process_paper_to_poster(
|
| 17 |
pdf_file,
|
| 18 |
model_choice,
|
|
|
|
| 68 |
output="" # 不再使用
|
| 69 |
)
|
| 70 |
|
| 71 |
+
# 检查返回值是否为None
|
| 72 |
+
if poster is None and html is None:
|
| 73 |
+
yield None, None, None, "❌ Failed to generate poster! The paper processing returned no results. Please check:\n- PDF file format and content\n- Figure detection service availability\n- API key validity\n- Model configuration\n- Network connectivity"
|
| 74 |
+
return
|
| 75 |
+
|
| 76 |
# 图片处理完毕,开始生成JSON
|
| 77 |
yield None, None, None, "🖼️ Image processing completed! Generating JSON structure..."
|
| 78 |
|
|
|
|
| 277 |
- Generated Poster is recommended to be viewed in fullscreen mode or download the HTML file to view in browser
|
| 278 |
- Requires a valid OpenAI API key with sufficient balance
|
| 279 |
- Figure detection service URL is required for extracting images from PDFs
|
| 280 |
+
- Processing time depends on paper length and complexity (usually 3-6 minutes)
|
| 281 |
- Ensure the model name is correct and supported by your API
|
| 282 |
- Download the HTML file and open it in your browser for the best viewing experience
|
| 283 |
|
main.py
CHANGED
|
@@ -74,6 +74,9 @@ def generate_paper_poster(
|
|
| 74 |
# with open(figures_cap_cache, "w") as f:
|
| 75 |
# json.dump(figures_cap, f, ensure_ascii=False)
|
| 76 |
|
|
|
|
|
|
|
|
|
|
| 77 |
while True:
|
| 78 |
try:
|
| 79 |
result = generate_poster_v3(
|
|
@@ -114,6 +117,10 @@ def generate_paper_poster(
|
|
| 114 |
):
|
| 115 |
raise
|
| 116 |
print(f"处理文件 {pdf} 时出错: {e}")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 117 |
|
| 118 |
|
| 119 |
if __name__ == "__main__":
|
|
|
|
| 74 |
# with open(figures_cap_cache, "w") as f:
|
| 75 |
# json.dump(figures_cap, f, ensure_ascii=False)
|
| 76 |
|
| 77 |
+
print("开始生成海报...")
|
| 78 |
+
max_attempts = 3
|
| 79 |
+
attempt = 0
|
| 80 |
while True:
|
| 81 |
try:
|
| 82 |
result = generate_poster_v3(
|
|
|
|
| 117 |
):
|
| 118 |
raise
|
| 119 |
print(f"处理文件 {pdf} 时出错: {e}")
|
| 120 |
+
attempt += 1
|
| 121 |
+
if attempt > max_attempts:
|
| 122 |
+
return None, None
|
| 123 |
+
|
| 124 |
|
| 125 |
|
| 126 |
if __name__ == "__main__":
|