Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
|
@@ -278,6 +278,8 @@ def submit_feedback():
|
|
| 278 |
# Content
|
| 279 |
# -----------------------
|
| 280 |
# ---------- Story Generation Endpoint ----------
|
|
|
|
|
|
|
| 281 |
@app.route('/api/story/generate', methods=['POST'])
|
| 282 |
def generate_story_endpoint():
|
| 283 |
try:
|
|
@@ -407,11 +409,15 @@ def generate_story_endpoint():
|
|
| 407 |
if input_type == "dataframe" and df is not None:
|
| 408 |
try:
|
| 409 |
chart_str = generateResponse(img_prompt, df)
|
|
|
|
| 410 |
if chart_str and chart_str.startswith("data:image/png;base64,"):
|
| 411 |
base64_data = chart_str.split(",", 1)[1]
|
| 412 |
-
|
|
|
|
| 413 |
image_obj = Image.open(io.BytesIO(chart_bytes))
|
|
|
|
| 414 |
except Exception as e:
|
|
|
|
| 415 |
print("DataFrame chart generation error:", e)
|
| 416 |
|
| 417 |
# Fallback to generate_image_with_retry
|
|
|
|
| 278 |
# Content
|
| 279 |
# -----------------------
|
| 280 |
# ---------- Story Generation Endpoint ----------
|
| 281 |
+
# Configure logging to write to a file
|
| 282 |
+
logging.basicConfig(filename=LOG_FILE_PATH, level=logging.DEBUG, format="%(asctime)s - %(levelname)s - %(message)s")
|
| 283 |
@app.route('/api/story/generate', methods=['POST'])
|
| 284 |
def generate_story_endpoint():
|
| 285 |
try:
|
|
|
|
| 409 |
if input_type == "dataframe" and df is not None:
|
| 410 |
try:
|
| 411 |
chart_str = generateResponse(img_prompt, df)
|
| 412 |
+
logging.info(f"chart string: {chart_str}")
|
| 413 |
if chart_str and chart_str.startswith("data:image/png;base64,"):
|
| 414 |
base64_data = chart_str.split(",", 1)[1]
|
| 415 |
+
logging.info(f"base64 data: {base64_data}")
|
| 416 |
+
chart_bytes = base64.b64decode(chart_bytes)
|
| 417 |
image_obj = Image.open(io.BytesIO(chart_bytes))
|
| 418 |
+
logging.info(f"Image: {image_obj})
|
| 419 |
except Exception as e:
|
| 420 |
+
logging.error(f"error {e}, DataFrame chart generation error")
|
| 421 |
print("DataFrame chart generation error:", e)
|
| 422 |
|
| 423 |
# Fallback to generate_image_with_retry
|