Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -60,32 +60,36 @@ def detect_context(text: str):
|
|
| 60 |
|
| 61 |
def process_and_translate(text: str):
|
| 62 |
detected_context = detect_context(text)
|
| 63 |
-
|
| 64 |
try:
|
| 65 |
-
|
|
|
|
| 66 |
translation_response = requests.post(
|
| 67 |
-
"https://
|
| 68 |
-
json={"data": [text]} #
|
| 69 |
-
)
|
| 70 |
|
| 71 |
-
|
|
|
|
|
|
|
| 72 |
return json.dumps({
|
| 73 |
-
"error": "
|
| 74 |
"context": detected_context
|
| 75 |
})
|
| 76 |
|
|
|
|
| 77 |
return json.dumps({
|
| 78 |
"context": detected_context,
|
| 79 |
-
"translation":
|
| 80 |
})
|
| 81 |
|
| 82 |
except Exception as e:
|
| 83 |
return json.dumps({
|
| 84 |
-
"error": str(e),
|
| 85 |
"context": detected_context
|
| 86 |
})
|
| 87 |
|
| 88 |
|
|
|
|
| 89 |
# Define Gradio interface
|
| 90 |
with gr.Blocks() as interface:
|
| 91 |
input_text = gr.Textbox(label="Input Text")
|
|
|
|
| 60 |
|
| 61 |
def process_and_translate(text: str):
|
| 62 |
detected_context = detect_context(text)
|
|
|
|
| 63 |
try:
|
| 64 |
+
print(f"Sending to space_7: {text}") # Debugging
|
| 65 |
+
|
| 66 |
translation_response = requests.post(
|
| 67 |
+
"https://api.gradio.app/v2/Frenchizer/space_7/predict",
|
| 68 |
+
json={"data": [text]} # Make sure this is correctly formatted
|
| 69 |
+
)
|
| 70 |
|
| 71 |
+
print("Raw response from space_7:", translation_response.text) # Debugging
|
| 72 |
+
|
| 73 |
+
if translation_response.status_code != 200 or not translation_response.text.strip():
|
| 74 |
return json.dumps({
|
| 75 |
+
"error": "space_7 returned an empty response",
|
| 76 |
"context": detected_context
|
| 77 |
})
|
| 78 |
|
| 79 |
+
response_json = translation_response.json()
|
| 80 |
return json.dumps({
|
| 81 |
"context": detected_context,
|
| 82 |
+
"translation": response_json.get("data", [""])[0]
|
| 83 |
})
|
| 84 |
|
| 85 |
except Exception as e:
|
| 86 |
return json.dumps({
|
| 87 |
+
"error": f"Exception: {str(e)}",
|
| 88 |
"context": detected_context
|
| 89 |
})
|
| 90 |
|
| 91 |
|
| 92 |
+
|
| 93 |
# Define Gradio interface
|
| 94 |
with gr.Blocks() as interface:
|
| 95 |
input_text = gr.Textbox(label="Input Text")
|