Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -84,7 +84,21 @@ css_overrides = """
|
|
| 84 |
}
|
| 85 |
"""
|
| 86 |
|
| 87 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 88 |
|
| 89 |
|
| 90 |
# --- Enhanced Configuration ---
|
|
@@ -302,6 +316,7 @@ def convert_code(
|
|
| 302 |
# Create client and prompt
|
| 303 |
client = openai.OpenAI(base_url="https://openrouter.ai/api/v1", api_key=api_key)
|
| 304 |
prompt = create_conversion_prompt(source_code, source_lang, target_lang)
|
|
|
|
| 305 |
|
| 306 |
try:
|
| 307 |
# Make the API call
|
|
|
|
| 84 |
}
|
| 85 |
"""
|
| 86 |
|
| 87 |
+
# --- Helper Functions ---
|
| 88 |
+
# -*- coding: utf-8 -*-
|
| 89 |
+
def sanitize_for_api(s: str) -> str:
|
| 90 |
+
"""
|
| 91 |
+
Turn any “smart quotes” into plain ASCII quotes (and similarly
|
| 92 |
+
for the common apostrophes) so we never slip non-ASCII into
|
| 93 |
+
our JSON encoder.
|
| 94 |
+
"""
|
| 95 |
+
return (
|
| 96 |
+
s
|
| 97 |
+
.replace("\u201c", '"')
|
| 98 |
+
.replace("\u201d", '"')
|
| 99 |
+
.replace("\u2018", "'")
|
| 100 |
+
.replace("\u2019", "'")
|
| 101 |
+
)
|
| 102 |
|
| 103 |
|
| 104 |
# --- Enhanced Configuration ---
|
|
|
|
| 316 |
# Create client and prompt
|
| 317 |
client = openai.OpenAI(base_url="https://openrouter.ai/api/v1", api_key=api_key)
|
| 318 |
prompt = create_conversion_prompt(source_code, source_lang, target_lang)
|
| 319 |
+
prompt = sanitize_for_api(prompt)
|
| 320 |
|
| 321 |
try:
|
| 322 |
# Make the API call
|