Spaces:
Runtime error
Runtime error
created the app
Browse files
app.py
ADDED
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import pandas as pd
|
3 |
+
from tqdm import tqdm
|
4 |
+
from facility_predict import Preprocess, Facility_Model, obj_Facility_Model, processor
|
5 |
+
|
6 |
+
def predict_batch_from_csv(input_file, output_file):
|
7 |
+
# Load batch data from CSV
|
8 |
+
batch_data = pd.read_csv(input_file)
|
9 |
+
|
10 |
+
# Initialize predictions list
|
11 |
+
predictions = []
|
12 |
+
|
13 |
+
# Iterate over rows with tqdm for progress tracking
|
14 |
+
for _, row in tqdm(batch_data.iterrows(), total=len(batch_data)):
|
15 |
+
text = row['facility_name'] # Replace 'facility_name' with the actual column name containing the text data
|
16 |
+
cleaned_text = processor.clean_text(text)
|
17 |
+
prepared_data = processor.process_tokenizer(cleaned_text)
|
18 |
+
prediction = obj_Facility_Model.inference(prepared_data)
|
19 |
+
predictions.append(prediction)
|
20 |
+
|
21 |
+
# Create DataFrame for predictions
|
22 |
+
output_data = pd.DataFrame({'prediction': predictions})
|
23 |
+
# Merge with input DataFrame
|
24 |
+
pred_output_df = pd.concat([batch_data, output_data], axis=1)
|
25 |
+
# Save predictions to CSV
|
26 |
+
pred_output_df.to_csv(output_file, index=False)
|
27 |
+
|
28 |
+
def predict_batch(input_csv, output_csv):
|
29 |
+
predict_batch_from_csv(input_csv, output_csv)
|
30 |
+
return "Prediction completed. Results saved to " + output_csv
|
31 |
+
|
32 |
+
iface = gr.Interface(
|
33 |
+
fn=predict_batch,
|
34 |
+
inputs=["file", "text"],
|
35 |
+
outputs="text",
|
36 |
+
title="Batch Facility Name Prediction",
|
37 |
+
description="Upload a CSV file with facility names and get the predictions in a CSV file",
|
38 |
+
examples=[["input.csv", "output.csv"]],
|
39 |
+
)
|
40 |
+
|
41 |
+
if __name__ == "__main__":
|
42 |
+
iface.launch()
|