Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -166,7 +166,20 @@ def predict(text):
|
|
| 166 |
|
| 167 |
combined_prediction = f"Level1: {predicted_label_level1} - Level2: {predicted_label_level2}"
|
| 168 |
return combined_prediction
|
| 169 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 170 |
|
| 171 |
# Define the markdown text with bullet points
|
| 172 |
markdown_text = """
|
|
@@ -174,6 +187,12 @@ markdown_text = """
|
|
| 174 |
- Input one budget line per time with min 2 words.
|
| 175 |
- Accuracy of the model is ~88%.
|
| 176 |
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 177 |
html_table = """
|
| 178 |
<h2 style="text-align: center;">COFOG Budget AutoClassification</h2>
|
| 179 |
<p style="text-align: justify; margin-left: 30px; margin-right: 30px;">
|
|
@@ -237,8 +256,8 @@ html_table = """
|
|
| 237 |
</table>
|
| 238 |
</div>
|
| 239 |
"""
|
| 240 |
-
|
| 241 |
-
|
| 242 |
fn=predict,
|
| 243 |
inputs=gr.components.Textbox(lines=1, placeholder="Enter Budget line here...", label="Budget Input"),
|
| 244 |
outputs=gr.components.Label(label="Classification Output"),
|
|
@@ -251,6 +270,23 @@ iface = gr.Interface(
|
|
| 251 |
|
| 252 |
)
|
| 253 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 254 |
# Run the interface
|
| 255 |
if __name__ == "__main__":
|
| 256 |
-
|
|
|
|
| 166 |
|
| 167 |
combined_prediction = f"Level1: {predicted_label_level1} - Level2: {predicted_label_level2}"
|
| 168 |
return combined_prediction
|
| 169 |
+
|
| 170 |
+
def classify_csv(file_obj):
|
| 171 |
+
# Read the CSV file
|
| 172 |
+
df = pd.read_csv(file_obj)
|
| 173 |
+
|
| 174 |
+
# Assuming you have a column 'text' in your CSV that you want to classify
|
| 175 |
+
predictions = []
|
| 176 |
+
for _, row in df.iterrows():
|
| 177 |
+
prediction = predict(row['text'])
|
| 178 |
+
predictions.append(prediction)
|
| 179 |
+
|
| 180 |
+
# Convert the predictions to a DataFrame
|
| 181 |
+
results_df = pd.DataFrame(predictions, columns=["Prediction"])
|
| 182 |
+
return results_df
|
| 183 |
|
| 184 |
# Define the markdown text with bullet points
|
| 185 |
markdown_text = """
|
|
|
|
| 187 |
- Input one budget line per time with min 2 words.
|
| 188 |
- Accuracy of the model is ~88%.
|
| 189 |
"""
|
| 190 |
+
markdown_text_file_upload = """
|
| 191 |
+
- Trained with ~1500 rows of data on bert-base-uncased, English.
|
| 192 |
+
- Upload CSV ONLY and name your column with budget line item as **text**.
|
| 193 |
+
- Added RAG (Retrieval-augmented generation) to feed context into classifier using preceing lines of budget.
|
| 194 |
+
- Accuracy of the model is ~88%.
|
| 195 |
+
"""
|
| 196 |
html_table = """
|
| 197 |
<h2 style="text-align: center;">COFOG Budget AutoClassification</h2>
|
| 198 |
<p style="text-align: justify; margin-left: 30px; margin-right: 30px;">
|
|
|
|
| 256 |
</table>
|
| 257 |
</div>
|
| 258 |
"""
|
| 259 |
+
# First interface for single line input
|
| 260 |
+
iface1 = gr.Interface(
|
| 261 |
fn=predict,
|
| 262 |
inputs=gr.components.Textbox(lines=1, placeholder="Enter Budget line here...", label="Budget Input"),
|
| 263 |
outputs=gr.components.Label(label="Classification Output"),
|
|
|
|
| 270 |
|
| 271 |
)
|
| 272 |
|
| 273 |
+
|
| 274 |
+
# Second interface (for CSV file upload)
|
| 275 |
+
iface2 = gr.Interface(
|
| 276 |
+
fn=classify_csv,
|
| 277 |
+
inputs=gr.components.File(label="Upload CSV File"),
|
| 278 |
+
outputs=gr.components.DataFrame(label="Classification Results"),
|
| 279 |
+
description=markdown_text_file_upload,
|
| 280 |
+
article=html_table,
|
| 281 |
+
title="Batch Classification"
|
| 282 |
+
)
|
| 283 |
+
|
| 284 |
+
# Combine the interfaces in a tabbed interface
|
| 285 |
+
tabbed_interface = gr.TabbedInterface(
|
| 286 |
+
[iface1, iface2],
|
| 287 |
+
["Single Prediction", "Batch Prediction"]
|
| 288 |
+
)
|
| 289 |
+
|
| 290 |
# Run the interface
|
| 291 |
if __name__ == "__main__":
|
| 292 |
+
tabbed_interface.launch()
|