Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1532,65 +1532,6 @@ Provide specific solutions for each issue."""
|
|
1532 |
error_msg += f" - {error_data['error']}"
|
1533 |
elif 'message' in error_data:
|
1534 |
error_msg += f" - {error_data['message']}"
|
1535 |
-
except Exception as e:
|
1536 |
-
logger.error(f"Error parsing error response: {e}")
|
1537 |
-
error_msg += f" - {response.text[:200]}"
|
1538 |
-
|
1539 |
-
yield f"❌ {error_msg}"
|
1540 |
-
return
|
1541 |
-
|
1542 |
-
buffer = ""
|
1543 |
-
line_count = 0
|
1544 |
-
|
1545 |
-
for line in response.iter_lines():
|
1546 |
-
if not line:
|
1547 |
-
continue
|
1548 |
-
|
1549 |
-
line_count += 1
|
1550 |
-
|
1551 |
-
try:
|
1552 |
-
line_str = line.decode('utf-8').strip()
|
1553 |
-
|
1554 |
-
# Skip non-SSE lines
|
1555 |
-
if not line_str.startswith("data: "):
|
1556 |
-
logger.debug(f"Skipping non-SSE line: {line_str[:50]}")
|
1557 |
-
continue
|
1558 |
-
|
1559 |
-
data_str = line_str[6:] # Remove "data: " prefix
|
1560 |
-
|
1561 |
-
if data_str == "[DONE]":
|
1562 |
-
logger.info(f"Stream completed. Total lines: {line_count}")
|
1563 |
-
break
|
1564 |
-
|
1565 |
-
if not data_str:
|
1566 |
-
continue
|
1567 |
-
|
1568 |
-
# Parse JSON data
|
1569 |
-
try:
|
1570 |
-
data = json.loads(data_str)
|
1571 |
-
except json.JSONDecodeError as e:
|
1572 |
-
logger.warning(f"JSON decode error on line {line_count}: {e}")
|
1573 |
-
logger.debug(f"Problematic data: {data_str[:100]}")
|
1574 |
-
continue
|
1575 |
-
|
1576 |
-
# Extract content from response
|
1577 |
-
if isinstance(data, dict) and "choices" in data:
|
1578 |
-
choices = data["choices"]
|
1579 |
-
if isinstance(choices, list) and len(choices) > 0:
|
1580 |
-
choice = choices[0]
|
1581 |
-
if isinstance(choice, dict) and "delta" in choice:
|
1582 |
-
delta = choice["delta"]
|
1583 |
-
if isinstance(delta, dict) and "content" in delta:
|
1584 |
-
content = delta["content"]
|
1585 |
-
if content:
|
1586 |
-
buffer += content
|
1587 |
-
|
1588 |
-
# Yield when buffer is large enough
|
1589 |
-
if len(buffer) >= 50 or '\n' in buffer:
|
1590 |
-
yield buffer
|
1591 |
-
buffer = ""
|
1592 |
-
time.sleep(0.01)
|
1593 |
-
|
1594 |
except Exception as e:
|
1595 |
logger.error(f"Error processing line {line_count}: {str(e)}")
|
1596 |
logger.debug(f"Problematic line: {line_str[:100] if 'line_str' in locals() else 'N/A'}")
|
@@ -1889,10 +1830,10 @@ You provide feedback that's critical yet encouraging."""
|
|
1889 |
if name_match:
|
1890 |
extracted_name = name_match.group(1).strip()
|
1891 |
# Remove markdown and extra characters
|
1892 |
-
extracted_name = re.sub(r'[*:\s]
|
1893 |
extracted_name = re.sub(r'^[*:\s]+', '', extracted_name)
|
1894 |
# Remove age if it's part of the name
|
1895 |
-
extracted_name = re.sub(r'\s*,?\s*\d+\s*(?:세|살)
|
1896 |
if extracted_name and len(extracted_name) > 1:
|
1897 |
name = extracted_name
|
1898 |
break
|
@@ -2007,7 +1948,66 @@ You provide feedback that's critical yet encouraging."""
|
|
2007 |
value = re.sub(r'\*\*', '', value)
|
2008 |
value = re.sub(r'^\s*[-•*]\s*', '', value)
|
2009 |
# Remove trailing punctuation
|
2010 |
-
value = re.sub(r'[,.:;]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2011 |
cleaned = value.strip()
|
2012 |
if cleaned:
|
2013 |
return cleaned
|
@@ -2395,7 +2395,66 @@ def format_screenplay_display(screenplay_text: str) -> str:
|
|
2395 |
|
2396 |
# Format scene headings
|
2397 |
formatted_text = re.sub(
|
2398 |
-
r'^(INT\.|EXT\.)(.*?)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2399 |
r'**\1\2**',
|
2400 |
screenplay_text,
|
2401 |
flags=re.MULTILINE
|
@@ -2403,7 +2462,66 @@ def format_screenplay_display(screenplay_text: str) -> str:
|
|
2403 |
|
2404 |
# Format character names (all caps on their own line)
|
2405 |
formatted_text = re.sub(
|
2406 |
-
r'^([A-Z][A-Z\s]+)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2407 |
r'**\1**',
|
2408 |
formatted_text,
|
2409 |
flags=re.MULTILINE
|
@@ -2871,5 +2989,4 @@ if __name__ == "__main__":
|
|
2871 |
server_port=7860,
|
2872 |
share=False,
|
2873 |
debug=True
|
2874 |
-
)
|
2875 |
-
|
|
|
1532 |
error_msg += f" - {error_data['error']}"
|
1533 |
elif 'message' in error_data:
|
1534 |
error_msg += f" - {error_data['message']}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1535 |
except Exception as e:
|
1536 |
logger.error(f"Error processing line {line_count}: {str(e)}")
|
1537 |
logger.debug(f"Problematic line: {line_str[:100] if 'line_str' in locals() else 'N/A'}")
|
|
|
1830 |
if name_match:
|
1831 |
extracted_name = name_match.group(1).strip()
|
1832 |
# Remove markdown and extra characters
|
1833 |
+
extracted_name = re.sub(r'[*:\s]+', '', extracted_name)
|
1834 |
extracted_name = re.sub(r'^[*:\s]+', '', extracted_name)
|
1835 |
# Remove age if it's part of the name
|
1836 |
+
extracted_name = re.sub(r'\s*,?\s*\d+\s*(?:세|살)?', '', extracted_name)
|
1837 |
if extracted_name and len(extracted_name) > 1:
|
1838 |
name = extracted_name
|
1839 |
break
|
|
|
1948 |
value = re.sub(r'\*\*', '', value)
|
1949 |
value = re.sub(r'^\s*[-•*]\s*', '', value)
|
1950 |
# Remove trailing punctuation
|
1951 |
+
value = re.sub(r'[,.:;]error(f"Error parsing error response: {e}")
|
1952 |
+
error_msg += f" - {response.text[:200]}"
|
1953 |
+
|
1954 |
+
yield f"❌ {error_msg}"
|
1955 |
+
return
|
1956 |
+
|
1957 |
+
buffer = ""
|
1958 |
+
line_count = 0
|
1959 |
+
|
1960 |
+
for line in response.iter_lines():
|
1961 |
+
if not line:
|
1962 |
+
continue
|
1963 |
+
|
1964 |
+
line_count += 1
|
1965 |
+
|
1966 |
+
try:
|
1967 |
+
line_str = line.decode('utf-8').strip()
|
1968 |
+
|
1969 |
+
# Skip non-SSE lines
|
1970 |
+
if not line_str.startswith("data: "):
|
1971 |
+
logger.debug(f"Skipping non-SSE line: {line_str[:50]}")
|
1972 |
+
continue
|
1973 |
+
|
1974 |
+
data_str = line_str[6:] # Remove "data: " prefix
|
1975 |
+
|
1976 |
+
if data_str == "[DONE]":
|
1977 |
+
logger.info(f"Stream completed. Total lines: {line_count}")
|
1978 |
+
break
|
1979 |
+
|
1980 |
+
if not data_str:
|
1981 |
+
continue
|
1982 |
+
|
1983 |
+
# Parse JSON data
|
1984 |
+
try:
|
1985 |
+
data = json.loads(data_str)
|
1986 |
+
except json.JSONDecodeError as e:
|
1987 |
+
logger.warning(f"JSON decode error on line {line_count}: {e}")
|
1988 |
+
logger.debug(f"Problematic data: {data_str[:100]}")
|
1989 |
+
continue
|
1990 |
+
|
1991 |
+
# Extract content from response
|
1992 |
+
if isinstance(data, dict) and "choices" in data:
|
1993 |
+
choices = data["choices"]
|
1994 |
+
if isinstance(choices, list) and len(choices) > 0:
|
1995 |
+
choice = choices[0]
|
1996 |
+
if isinstance(choice, dict) and "delta" in choice:
|
1997 |
+
delta = choice["delta"]
|
1998 |
+
if isinstance(delta, dict) and "content" in delta:
|
1999 |
+
content = delta["content"]
|
2000 |
+
if content:
|
2001 |
+
buffer += content
|
2002 |
+
|
2003 |
+
# Yield when buffer is large enough
|
2004 |
+
if len(buffer) >= 50 or '\n' in buffer:
|
2005 |
+
yield buffer
|
2006 |
+
buffer = ""
|
2007 |
+
time.sleep(0.01)
|
2008 |
+
|
2009 |
+
except Exception as e:
|
2010 |
+
logger., '', value)
|
2011 |
cleaned = value.strip()
|
2012 |
if cleaned:
|
2013 |
return cleaned
|
|
|
2395 |
|
2396 |
# Format scene headings
|
2397 |
formatted_text = re.sub(
|
2398 |
+
r'^(INT\.|EXT\.)(.*?)error(f"Error parsing error response: {e}")
|
2399 |
+
error_msg += f" - {response.text[:200]}"
|
2400 |
+
|
2401 |
+
yield f"❌ {error_msg}"
|
2402 |
+
return
|
2403 |
+
|
2404 |
+
buffer = ""
|
2405 |
+
line_count = 0
|
2406 |
+
|
2407 |
+
for line in response.iter_lines():
|
2408 |
+
if not line:
|
2409 |
+
continue
|
2410 |
+
|
2411 |
+
line_count += 1
|
2412 |
+
|
2413 |
+
try:
|
2414 |
+
line_str = line.decode('utf-8').strip()
|
2415 |
+
|
2416 |
+
# Skip non-SSE lines
|
2417 |
+
if not line_str.startswith("data: "):
|
2418 |
+
logger.debug(f"Skipping non-SSE line: {line_str[:50]}")
|
2419 |
+
continue
|
2420 |
+
|
2421 |
+
data_str = line_str[6:] # Remove "data: " prefix
|
2422 |
+
|
2423 |
+
if data_str == "[DONE]":
|
2424 |
+
logger.info(f"Stream completed. Total lines: {line_count}")
|
2425 |
+
break
|
2426 |
+
|
2427 |
+
if not data_str:
|
2428 |
+
continue
|
2429 |
+
|
2430 |
+
# Parse JSON data
|
2431 |
+
try:
|
2432 |
+
data = json.loads(data_str)
|
2433 |
+
except json.JSONDecodeError as e:
|
2434 |
+
logger.warning(f"JSON decode error on line {line_count}: {e}")
|
2435 |
+
logger.debug(f"Problematic data: {data_str[:100]}")
|
2436 |
+
continue
|
2437 |
+
|
2438 |
+
# Extract content from response
|
2439 |
+
if isinstance(data, dict) and "choices" in data:
|
2440 |
+
choices = data["choices"]
|
2441 |
+
if isinstance(choices, list) and len(choices) > 0:
|
2442 |
+
choice = choices[0]
|
2443 |
+
if isinstance(choice, dict) and "delta" in choice:
|
2444 |
+
delta = choice["delta"]
|
2445 |
+
if isinstance(delta, dict) and "content" in delta:
|
2446 |
+
content = delta["content"]
|
2447 |
+
if content:
|
2448 |
+
buffer += content
|
2449 |
+
|
2450 |
+
# Yield when buffer is large enough
|
2451 |
+
if len(buffer) >= 50 or '\n' in buffer:
|
2452 |
+
yield buffer
|
2453 |
+
buffer = ""
|
2454 |
+
time.sleep(0.01)
|
2455 |
+
|
2456 |
+
except Exception as e:
|
2457 |
+
logger.,
|
2458 |
r'**\1\2**',
|
2459 |
screenplay_text,
|
2460 |
flags=re.MULTILINE
|
|
|
2462 |
|
2463 |
# Format character names (all caps on their own line)
|
2464 |
formatted_text = re.sub(
|
2465 |
+
r'^([A-Z][A-Z\s]+)error(f"Error parsing error response: {e}")
|
2466 |
+
error_msg += f" - {response.text[:200]}"
|
2467 |
+
|
2468 |
+
yield f"❌ {error_msg}"
|
2469 |
+
return
|
2470 |
+
|
2471 |
+
buffer = ""
|
2472 |
+
line_count = 0
|
2473 |
+
|
2474 |
+
for line in response.iter_lines():
|
2475 |
+
if not line:
|
2476 |
+
continue
|
2477 |
+
|
2478 |
+
line_count += 1
|
2479 |
+
|
2480 |
+
try:
|
2481 |
+
line_str = line.decode('utf-8').strip()
|
2482 |
+
|
2483 |
+
# Skip non-SSE lines
|
2484 |
+
if not line_str.startswith("data: "):
|
2485 |
+
logger.debug(f"Skipping non-SSE line: {line_str[:50]}")
|
2486 |
+
continue
|
2487 |
+
|
2488 |
+
data_str = line_str[6:] # Remove "data: " prefix
|
2489 |
+
|
2490 |
+
if data_str == "[DONE]":
|
2491 |
+
logger.info(f"Stream completed. Total lines: {line_count}")
|
2492 |
+
break
|
2493 |
+
|
2494 |
+
if not data_str:
|
2495 |
+
continue
|
2496 |
+
|
2497 |
+
# Parse JSON data
|
2498 |
+
try:
|
2499 |
+
data = json.loads(data_str)
|
2500 |
+
except json.JSONDecodeError as e:
|
2501 |
+
logger.warning(f"JSON decode error on line {line_count}: {e}")
|
2502 |
+
logger.debug(f"Problematic data: {data_str[:100]}")
|
2503 |
+
continue
|
2504 |
+
|
2505 |
+
# Extract content from response
|
2506 |
+
if isinstance(data, dict) and "choices" in data:
|
2507 |
+
choices = data["choices"]
|
2508 |
+
if isinstance(choices, list) and len(choices) > 0:
|
2509 |
+
choice = choices[0]
|
2510 |
+
if isinstance(choice, dict) and "delta" in choice:
|
2511 |
+
delta = choice["delta"]
|
2512 |
+
if isinstance(delta, dict) and "content" in delta:
|
2513 |
+
content = delta["content"]
|
2514 |
+
if content:
|
2515 |
+
buffer += content
|
2516 |
+
|
2517 |
+
# Yield when buffer is large enough
|
2518 |
+
if len(buffer) >= 50 or '\n' in buffer:
|
2519 |
+
yield buffer
|
2520 |
+
buffer = ""
|
2521 |
+
time.sleep(0.01)
|
2522 |
+
|
2523 |
+
except Exception as e:
|
2524 |
+
logger.,
|
2525 |
r'**\1**',
|
2526 |
formatted_text,
|
2527 |
flags=re.MULTILINE
|
|
|
2989 |
server_port=7860,
|
2990 |
share=False,
|
2991 |
debug=True
|
2992 |
+
)
|
|