Delaying in receiving data from server

Hi,

I am facing problem with delaying response time in generating data frm my local host server. (display
the data in Anvil web page).
I fire some parameters from client (Anvil) and submit to my server (Jupyter notebook), it will generate
5 data and send them back.
At the client side, however, I need to wait some times to get the 5 data from server. (response time a bit slow).
Any way to speed up the data displaying time?

This is my client side code.

if self.drop_down_3.selected_value =="abc":
    param_text = str(self.drop_down_4.selected_value) + ',' + str(self.drop_down_5.selected_value) + ',' + str(self.text_box_5.text)



preds_data1=anvil.server.call('predictABC',param_text)
preds_data2=anvil.server.call('predictABC',param_text)
preds_data3=anvil.server.call('predictABC',param_text)
preds_data4=anvil.server.call('predictABC',param_text)
preds_data5=anvil.server.call('predictABC',param_text)

if preds_data1:    
  self.text_area_1.visible = True
  self.text_area_1.text = preds_data1
if preds_data2:    
  self.text_area_2.visible = True
  self.text_area_2.text = preds_data2
if preds_data3:    
  self.text_area_3.visible = True
  self.text_area_3.text = preds_data3
if preds_data4:    
  self.text_area_4.visible = True
  self.text_area_4.text = preds_data4  
if preds_data5:    
  self.text_area_5.visible = True
  self.text_area_5.text = preds_data5  


Server side code that send the 5 data back to Anvil:    

preds = model.predict([query])
   for pred in preds[0]:
       return(str(pred))

Please advise. TQ.

Server calls have a communications overhead, so you never want to make multiple server calls when one would do. Combine your server calls into a single call, and return a dictionary or list of results.

2 Likes

Thanks for reply.
My return result frm notebook to Anvil is is 5 different data.
If I use a single server call: (preds_data1=anvil.server.call(‘predictABC’,param_text)), how should I separate the 5 data into different text_area?

Currently result returned one by one (that’s why slow).

Please help thanks.

That’s quite easy. You just need to send a list containing all 5 data and set it to your Text Area like this.

self.text_area_1.text=preds_data1[0]
self.text_area_2.text=preds_data1[1]
self.text_area_3.text=preds_data1[2]
...

Or maybe you can iterate through the elements of the list.

1 Like

The return from my jupyter notebook is 5 different sentences. (its working in jupyter notebook, can print 5 lines of sentences using the looping)

If I use:

self.text_area_1.text=preds_data1[0]
self.text_area_2.text=preds_data1[1]
self.text_area_3.text=preds_data1[2]

The result:
self.text_area_1.text=W
self.text_area_2.text=h
self.text_area_3.text=a
self.text_area_4.text=t

Seems like it get the wording one by one from the 1st sentence.
The issue is with this line:

preds_data1=anvil.server.call(‘predictABC’,param_text)

where by, it can only capture one sentence only each time from server, even if 5 sentences returned.

Pls help. Thx.

If I return the whole bundle of 5 set of data, then the value for preds_data will loos like this:

[[‘What is xxx xxx?’, ‘The box is xxx xxx.’, ‘I am fine xxx xxx’,‘Here you are xx xxx’,‘Police xxx xxx.’]]

Question:
How to 'chop '/ separate the 5 sentences here, to display in the 5 text_areas respectively? ?

You need the split() function for this. It will split a string into a list of substrings. Normally, it goes like this:

list_of_sentence = ‘Hello. How are you’.split(’.’)

But if you want to split a string based on multiple parameters, you can try the re.split() method.

In your case, this code should work

import re
list_of_sentences=re.split('[!.?]',preds_data)

hmm… still in whole bundle of data.

my sentence actually quite long, for exmaple:

The AnVIL is cloud computing resource developed in part by the National Human Genome Research Institute. The AnVIL package provides end-user and developer functionality.

can consist of few sentences., with , . and ?

Can you please provide me more information. Like share an updated code snippet based on my solution?

You can add more punctuation here as well.

list_of_sentences=re.split('[!.?,;]',preds_data)

I ‘hang’ at this step: how to separate the sentence after this line… so that each sentence can be display in my text area (5 text area fields).

list_of_sentences=re.split(’[!.?,;]’,preds_data)

code sample (no idea on how to capture the list_of_sentences):

if list_of_sentences:
self.text_area_1.visible = True
self.text_area_1.text = xxx
if list_of_sentences:
self.text_area_2.visible = True
self.text_area_2.text = yyy

here is what you can do.

self.text_area_1.text=list_of_sentences[0]
self.text_area_2.text=list_of_sentences[1]
self.text_area_3.text=list_of_sentences[2]
...

result:

only the first sentence display, and split over self.text_area_1,self.text_area_2,self.text_area_3.
Means each text_area got some wording…

Can you please provide some clone link, screenshots or more details here. It is getting hard for me to help you due to lack of information.

May I know how to send to you the link privately?

Okay, looks like you are returning a list which contains another list containing the sentences.

So, before calling the re.split(), you need to do this

preds_data=preds_data[0]

Edit: I realized that the re.split() method may be unnecessary since you already maybe returning separate sentences. So just try this and let me know the results.

data=preds_data[0]
self.text_area_1.text=data[0]
self.text_area_2.text=data[1]
self.text_area_3.text=data[2]
...

At this point, you require some debugging to make yourselves aware with what is actually happening here.

Can you please

print(data) 

and show me the output of it?