I am processing a pandas dataframe on the server-side which takes a pretty much good amount of time. It's very easy to display the progress of the task on the server-side (on the terminal) using tqdm. Like following code snippet:
def item_class_phen_pred(df, dataset_name):
predicted_class_name = []
sentence = []
tokenizer, device, model, reverse_dict = dispatch_models(dataset_name)
for i, row in tqdm(df.iterrows(), total=df.shape[0]):
_, _, predicted_class = predict(row["Comment"], model, tokenizer, device)
sentence.append(row["Comment"])
for key, val in reverse_dict.items():
if key == predicted_class:
predicted_class = val
predicted_class_name.append(predicted_class)
break
return predicted_class_name, sentence
Now, I want to display the progress rate on the client-side. Is it possible to store the progress of the task in a variable dynamically and pass it to the client-side. For tqdm, we don't need to anything, we can just pass the iterable to display the progress. But what I need to do if I want to pass the progress rate on the client-side?
For example, like below?
from flask import Flask, render_template, Response
import time, math
from tqdm import tqdm
app = Flask(__name__)
@app.route('/content') # render the content a url differnt from index
def content():
def inner():
# simulate a long process to watch
for i in tqdm(range(100)):
time.sleep(1)
# this value should be inserted into an HTML template
yield str(i)
return Response(inner(), mimetype='text/html')
@app.route('/')
def index():
return render_template('index.html')
template code:
<div>
<iframe frameborder="0" noresize="noresize"
style='background: transparent; width: 100%; height:100%;'
src="{{ url_for('content')}}">
</iframe>
</div>
I found the above example in this answer.
I am using flask on the server-side. Any help would be highly appreciated.