Frenchizer commited on
Commit
094d492
·
verified ·
1 Parent(s): 29fafe0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -13
app.py CHANGED
@@ -39,35 +39,34 @@ def preprocess_text(text: str, is_spell_corrected: bool = False):
39
  "original": text,
40
  "corrected": capitalized_text
41
  })
42
- text = capitalized_text # Update text for further processing
43
 
44
- # Transformer spell check (other suggestions)
 
 
 
 
 
 
 
45
  spell_checked = spell_checker(text, max_length=512)[0]['generated_text']
46
  if spell_checked != text:
47
  result["other_suggestions"].append({
48
  "original": text,
49
  "corrected": spell_checked
50
  })
51
- text = spell_checked # Update text after spell correction
52
 
53
  # Add entities and tags
54
  doc = nlp(text)
55
  result["entities"] = [{"text": ent.text, "label": ent.label_} for ent in doc.ents]
56
  result["tags"] = [token.text for token in doc if token.text.startswith(('#', '@'))]
57
 
58
- return text, result
59
 
60
  def preprocess_and_forward(text: str, is_spell_corrected: bool = False):
61
  """Process text and forward to translation service."""
62
- original_text, preprocessing_result = preprocess_text(text, is_spell_corrected)
63
-
64
- # Forward original text to translation service
65
- client = Client("Frenchizer/space_21")
66
- try:
67
- translation = client.predict(original_text)
68
- return translation, preprocessing_result
69
- except Exception as e:
70
- return f"Error: {str(e)}", preprocessing_result
71
 
72
  # Gradio interface
73
  with gr.Blocks() as demo:
 
39
  "original": text,
40
  "corrected": capitalized_text
41
  })
42
+ text = capitalized_text # Update text after preprocessing
43
 
44
+ # Translate right after preprocessing
45
+ client = Client("Frenchizer/space_17")
46
+ try:
47
+ translation = client.predict(text)
48
+ except Exception as e:
49
+ translation = f"Error: {str(e)}"
50
+
51
+ # Transformer spell check (other suggestions), after translation
52
  spell_checked = spell_checker(text, max_length=512)[0]['generated_text']
53
  if spell_checked != text:
54
  result["other_suggestions"].append({
55
  "original": text,
56
  "corrected": spell_checked
57
  })
 
58
 
59
  # Add entities and tags
60
  doc = nlp(text)
61
  result["entities"] = [{"text": ent.text, "label": ent.label_} for ent in doc.ents]
62
  result["tags"] = [token.text for token in doc if token.text.startswith(('#', '@'))]
63
 
64
+ return translation, result
65
 
66
  def preprocess_and_forward(text: str, is_spell_corrected: bool = False):
67
  """Process text and forward to translation service."""
68
+ translation, preprocessing_result = preprocess_text(text, is_spell_corrected)
69
+ return translation, preprocessing_result
 
 
 
 
 
 
 
70
 
71
  # Gradio interface
72
  with gr.Blocks() as demo: