Skip to content

Commit d3ce0d7

Browse files
authored
Merge pull request #8 from JEENB/sendimage
everything works
2 parents f501e91 + 652c572 commit d3ce0d7

12 files changed

+100
-6
lines changed

__pycache__/models.cpython-38.pyc

0 Bytes
Binary file not shown.

app.py

+66-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,59 @@ def send_model_data():
102102
dpg.delete_item("original")
103103
with dpg.window(label="Example Window", width=width, height=height, tag="original", pos=pos):
104104
dpg.add_text("Data sent to server")
105-
dpg.add_text("Model is getting trained by the model.....")
105+
dpg.add_text("Model is getting trained by the server.....")
106+
107+
#receive image
108+
file_size = client.recv(1024).decode()
109+
110+
print(file_size)
111+
file_path = 'receivedFitting.png'
112+
file = open(file_path, "wb")
113+
c = 0
114+
# Starting the time capture.
115+
start_time = time.time()
116+
117+
# Running the loop while file is recieved.
118+
while c < int(file_size):
119+
data = client.recv(1024)
120+
if not (data):
121+
break
122+
file.write(data)
123+
c += len(data)
124+
file.close()
125+
126+
# Ending the time capture.
127+
end_time = time.time()
128+
129+
print("[INFO]: Fitting image file received. Total time: ", end_time - start_time)
130+
131+
#recv msg that model is trained. Show to GUI with text and image.
132+
#=====need to adjust image size
133+
dpg.delete_item("original")
134+
with dpg.window(label="Example Window", width=900, height=750, tag="original", pos=pos):
135+
dpg.add_text("Your model is trained. ")
136+
#show image
137+
width1, height1, channels, data = dpg.load_image('receivedFitting.png')
138+
139+
with dpg.texture_registry(show=True):
140+
dpg.add_static_texture(width1, height1, data, tag="texture_tag")
141+
dpg.add_image("texture_tag")
142+
# with dpg.window(label="Tutorial"):
143+
144+
145+
146+
147+
#show msg "finalising report...."
148+
# msg = client.recv(1024).decode()
149+
150+
dpg.add_text("finalising report...")
151+
152+
153+
154+
155+
156+
157+
106158

107159
#==============client code starts===========
108160
#Receive Report from server
@@ -129,8 +181,21 @@ def send_model_data():
129181
print("[INFO]: Report file received. Total time: ", end_time - start_time)
130182

131183

184+
185+
132186
#===========client code ends========
133187

188+
189+
#recreate the previous window along with received report's path
190+
# working_dir_path = os.getworkingdirectory()
191+
# new_file_path = working_dir_path + '/' + file_path
192+
193+
dpg.delete_item("original")
194+
with dpg.window(label="Example Window", width=900, height=750, tag="original", pos=pos):
195+
dpg.add_text("Your final report downloaded at location: " + str(file_path))
196+
197+
198+
134199
def get_model_inputs():
135200
pass
136201

models.py

-3
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,7 @@ def reg_training_model(df, user_dir, degree = 1, split_ratio = 0.2):
6868
plt.legend(loc='upper left')
6969
plt.title("Polynomial Fitting")
7070
plt.savefig(f"{user_dir}/fitting.png")
71-
<<<<<<< HEAD
7271
# plt.show()
73-
=======
74-
>>>>>>> 65771cfe70696bdfb5aef65df8cf3f8aa223ab0b
7572

7673

7774
##-------------------------------------------------

receivedFitting.png

29.9 KB
Loading

sentreport.pdf

1.08 KB
Binary file not shown.

server1.py

+34-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
import os
32
import socket
43
import time
@@ -76,6 +75,39 @@
7675

7776
tot, maxi, mini, mean, medi, sd = stats_summary(df)
7877
print("model training done......")
78+
79+
#send 1 image to client
80+
file_path = f'./server_data/{initial}/fitting.png'
81+
file_size = os.path.getsize(file_path)
82+
print(file_size)
83+
conn.send(str(file_size).encode())
84+
85+
86+
with open(file_path, "rb") as file:
87+
c = 0
88+
# Starting the time capture.
89+
start_time = time.time()
90+
91+
# Running loop while c != file_size.
92+
while c <= file_size:
93+
data = file.read(1024)
94+
if not (data):
95+
break
96+
conn.sendall(data)
97+
c += len(data)
98+
99+
# Ending the time capture.
100+
end_time = time.time()
101+
file.close()
102+
print("[INFO] Fitting image Transfer Complete.Total time: ", end_time - start_time)
103+
104+
105+
#client "finalising report......"
106+
# conn.send("finalising report....".encode())
107+
108+
#file report downloaded. Local path"receivedreport.pdf"
109+
110+
79111
c_report(tot, maxi, mini, mean, medi, sd, training_points, testing_points, degree, split = training_ratio, user_dir = user_dir)
80112
print(str(tot))
81113
print("report generated now")
@@ -102,7 +134,7 @@
102134

103135
# Ending the time capture.
104136
end_time = time.time()
105-
137+
file.close()
106138
print("[INFO] Report file Transfer Complete.Total time: ", end_time - start_time)
107139

108140

server_data/jen/actual_pred.png

-327 Bytes
Loading

server_data/jen/compare_error.png

1.62 KB
Loading

server_data/jen/fitting.png

1.43 KB
Loading

server_data/jen/normalqq.png

-1.18 KB
Loading

server_data/jen/report.pdf

1.08 KB
Binary file not shown.

server_data/jen/residual_pred.png

-464 Bytes
Loading

0 commit comments

Comments
 (0)