Alshargi commited on
Commit
f7c5c6f
·
verified ·
1 Parent(s): 8ebd7b5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -32
app.py CHANGED
@@ -113,35 +113,36 @@ def features(sentence, index):
113
  'is_numeric': sentence[index].isdigit(),
114
  }
115
 
116
- # Function to prepare text
117
- def prepare_text(text):
118
- symbol_pattern = r'([^\w\s\d])'
119
- prepared_text = re.sub(symbol_pattern, r' \1 ', text)
120
- prepared_text = re.sub(r'\s+', ' ', prepared_text)
121
- return prepared_text.strip()
122
-
123
- # Text input field for user input
124
- text_input = st.text_input("Enter some text:")
125
-
126
- # Check if the user input is not empty
127
- if text_input:
128
- # Prepare text
129
- prepared_text = prepare_text(text_input)
130
-
131
- # Tokenize text
132
- tokenized_text = word_tokenize(prepared_text)
133
-
134
- # Extract features
135
- features_list = [features(tokenized_text, i) for i in range(len(tokenized_text))]
136
-
137
- # Create a DataFrame with the features
138
- data = pd.DataFrame(features_list)
139
-
140
- # Load the model from the Hub
141
- model_id = "Alshargi/arabic-msa-dialects-segmentation"
142
- res = hub_utils.get_model_output(model_id, data)
143
-
144
- # Display the model output
145
- st.write("Model Output:", res)
146
- else:
147
- st.write("Please enter some text.")
 
 
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
+