Frenchizer commited on
Commit
f6b3235
·
verified ·
1 Parent(s): 6e24b14

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -9
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
- # Forward only text to space_18 later we will forward according to the context
 
66
  translation_response = requests.post(
67
- "https://huggingface.co/spaces/Frenchizer/space_18/predict",
68
- json={"data": [text]} # ⬅️ Now sending only `text`
69
- ).json()
70
 
71
- if "error" in translation_response:
 
 
72
  return json.dumps({
73
- "error": "Translation failed",
74
  "context": detected_context
75
  })
76
 
 
77
  return json.dumps({
78
  "context": detected_context,
79
- "translation": translation_response["data"][0]
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")