Update app.py
Browse files
app.py
CHANGED
|
@@ -113,35 +113,36 @@ def features(sentence, index):
|
|
| 113 |
'is_numeric': sentence[index].isdigit(),
|
| 114 |
}
|
| 115 |
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
|
|
|
|
|
| 113 |
'is_numeric': sentence[index].isdigit(),
|
| 114 |
}
|
| 115 |
|
| 116 |
+
import gradio as gr
|
| 117 |
+
|
| 118 |
+
# Define the function for processing user input
|
| 119 |
+
def process_text(text_input):
|
| 120 |
+
if text_input:
|
| 121 |
+
# Prepare text
|
| 122 |
+
prepared_text = prepare_text(text_input)
|
| 123 |
+
|
| 124 |
+
# Tokenize text
|
| 125 |
+
tokenized_text = word_tokenize(prepared_text)
|
| 126 |
+
|
| 127 |
+
# Extract features
|
| 128 |
+
features_list = [features(tokenized_text, i) for i in range(len(tokenized_text))]
|
| 129 |
+
|
| 130 |
+
# Create a DataFrame with the features
|
| 131 |
+
data = pd.DataFrame(features_list)
|
| 132 |
+
|
| 133 |
+
# Load the model from the Hub
|
| 134 |
+
model_id = "Alshargi/arabic-msa-dialects-segmentation"
|
| 135 |
+
res = hub_utils.get_model_output(model_id, data)
|
| 136 |
+
|
| 137 |
+
# Return the model output
|
| 138 |
+
return res
|
| 139 |
+
else:
|
| 140 |
+
return "Please enter some text."
|
| 141 |
+
|
| 142 |
+
# Define the Gradio interface
|
| 143 |
+
iface = gr.Interface(fn=process_text, inputs="text", outputs="text", title="Arabic Text Segmentation")
|
| 144 |
+
|
| 145 |
+
# Launch the Gradio interface
|
| 146 |
+
iface.launch()
|
| 147 |
+
|
| 148 |
+
|