Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -73,13 +73,13 @@ def filter_by_frequency(counts_dict: dict, threshold_percent: float = 0.2):
|
|
| 73 |
def simple_predict(text, num_predictions=3):
|
| 74 |
"""Simple language detection function for Gradio interface"""
|
| 75 |
if not text or not text.strip():
|
| 76 |
-
return "Please enter some text for language detection."
|
| 77 |
|
| 78 |
try:
|
| 79 |
# Clean the text
|
| 80 |
cleaned_lines = list(yield_clean_rows([text]))
|
| 81 |
if not cleaned_lines:
|
| 82 |
-
return "No valid text found after cleaning."
|
| 83 |
|
| 84 |
# Get predictions for each line
|
| 85 |
all_predictions = []
|
|
@@ -88,7 +88,7 @@ def simple_predict(text, num_predictions=3):
|
|
| 88 |
all_predictions.extend(predictions)
|
| 89 |
|
| 90 |
if not all_predictions:
|
| 91 |
-
return "No predictions could be made."
|
| 92 |
|
| 93 |
# Group predictions by language
|
| 94 |
predictions_by_lang = groupby(get_label, all_predictions)
|
|
@@ -108,18 +108,18 @@ def simple_predict(text, num_predictions=3):
|
|
| 108 |
return results
|
| 109 |
|
| 110 |
except Exception as e:
|
| 111 |
-
return f"Error during prediction: {str(e)}"
|
| 112 |
|
| 113 |
def batch_predict(text, threshold_percent=0.2):
|
| 114 |
"""More advanced prediction with filtering"""
|
| 115 |
if not text or not text.strip():
|
| 116 |
-
return "Please enter some text for language detection."
|
| 117 |
|
| 118 |
try:
|
| 119 |
# Clean the text
|
| 120 |
cleaned_lines = list(yield_clean_rows([text]))
|
| 121 |
if not cleaned_lines:
|
| 122 |
-
return "No valid text found after cleaning."
|
| 123 |
|
| 124 |
# Get predictions
|
| 125 |
predictions = [model_predict(line) for line in cleaned_lines]
|
|
@@ -127,7 +127,7 @@ def batch_predict(text, threshold_percent=0.2):
|
|
| 127 |
predictions = list(concat(predictions))
|
| 128 |
|
| 129 |
if not predictions:
|
| 130 |
-
return "No predictions could be made."
|
| 131 |
|
| 132 |
# Group and filter
|
| 133 |
predictions_by_lang = groupby(get_label, predictions)
|
|
@@ -145,7 +145,7 @@ def batch_predict(text, threshold_percent=0.2):
|
|
| 145 |
return results
|
| 146 |
|
| 147 |
except Exception as e:
|
| 148 |
-
return f"Error during prediction: {str(e)}"
|
| 149 |
|
| 150 |
def build_demo_interface():
|
| 151 |
app_title = "Language Detection Tool"
|
|
|
|
| 73 |
def simple_predict(text, num_predictions=3):
|
| 74 |
"""Simple language detection function for Gradio interface"""
|
| 75 |
if not text or not text.strip():
|
| 76 |
+
return {"error": "Please enter some text for language detection."}
|
| 77 |
|
| 78 |
try:
|
| 79 |
# Clean the text
|
| 80 |
cleaned_lines = list(yield_clean_rows([text]))
|
| 81 |
if not cleaned_lines:
|
| 82 |
+
return {"error": "No valid text found after cleaning."}
|
| 83 |
|
| 84 |
# Get predictions for each line
|
| 85 |
all_predictions = []
|
|
|
|
| 88 |
all_predictions.extend(predictions)
|
| 89 |
|
| 90 |
if not all_predictions:
|
| 91 |
+
return {"error": "No predictions could be made."}
|
| 92 |
|
| 93 |
# Group predictions by language
|
| 94 |
predictions_by_lang = groupby(get_label, all_predictions)
|
|
|
|
| 108 |
return results
|
| 109 |
|
| 110 |
except Exception as e:
|
| 111 |
+
return {"error": f"Error during prediction: {str(e)}"}
|
| 112 |
|
| 113 |
def batch_predict(text, threshold_percent=0.2):
|
| 114 |
"""More advanced prediction with filtering"""
|
| 115 |
if not text or not text.strip():
|
| 116 |
+
return {"error": "Please enter some text for language detection."}
|
| 117 |
|
| 118 |
try:
|
| 119 |
# Clean the text
|
| 120 |
cleaned_lines = list(yield_clean_rows([text]))
|
| 121 |
if not cleaned_lines:
|
| 122 |
+
return {"error": "No valid text found after cleaning."}
|
| 123 |
|
| 124 |
# Get predictions
|
| 125 |
predictions = [model_predict(line) for line in cleaned_lines]
|
|
|
|
| 127 |
predictions = list(concat(predictions))
|
| 128 |
|
| 129 |
if not predictions:
|
| 130 |
+
return {"error": "No predictions could be made."}
|
| 131 |
|
| 132 |
# Group and filter
|
| 133 |
predictions_by_lang = groupby(get_label, predictions)
|
|
|
|
| 145 |
return results
|
| 146 |
|
| 147 |
except Exception as e:
|
| 148 |
+
return {"error": f"Error during prediction: {str(e)}"}
|
| 149 |
|
| 150 |
def build_demo_interface():
|
| 151 |
app_title = "Language Detection Tool"
|