Update app.py
Browse files
app.py
CHANGED
|
@@ -938,6 +938,7 @@ def getdropdownValues(gc,spreadsheet_service,spreadsheetid):
|
|
| 938 |
dropdownValues.append(*dictVal)
|
| 939 |
print(dropdownValues)
|
| 940 |
worksheet.update_col(index=1, values=dropdownValues)
|
|
|
|
| 941 |
return dropdownValues
|
| 942 |
|
| 943 |
|
|
@@ -1066,15 +1067,16 @@ def legendGoogleSheets(path,SimilarAreaDictionary,colorsUsed):
|
|
| 1066 |
res = spreadsheet_service.spreadsheets().batchUpdate(spreadsheetId=spreadsheetId, body=body).execute()
|
| 1067 |
spreadsheet_url = "https://docs.google.com/spreadsheets/d/%s" % spreadsheetId
|
| 1068 |
print(spreadsheet_url)
|
|
|
|
| 1069 |
|
| 1070 |
-
return gc,spreadsheet_service,spreadsheetId
|
| 1071 |
|
| 1072 |
|
| 1073 |
|
| 1074 |
def MainFunc(plan,green2,img,dp,finalColorArray,number,num1,num2,flag):
|
| 1075 |
|
| 1076 |
imgPerimeter1,image_new1,Df2,colorsUsed=drawAllContours(plan,green2,img,number,finalColorArray,num1,num2,flag)
|
| 1077 |
-
gc,spreadsheet_service,spreadsheetId=legendGoogleSheets(plan,Df2,colorsUsed)
|
| 1078 |
# x = path.split("/")
|
| 1079 |
# x=x.pop()
|
| 1080 |
Df2=Df2.T
|
|
@@ -1094,7 +1096,7 @@ def MainFunc(plan,green2,img,dp,finalColorArray,number,num1,num2,flag):
|
|
| 1094 |
|
| 1095 |
# display(Df2)
|
| 1096 |
|
| 1097 |
-
return Df2, imgPerimeter1,image_new1
|
| 1098 |
|
| 1099 |
def PickColorContours(plan,dp,img,radioButton,radioButton1, color,color1,color2,color3,color4,color5,color6,color7,color8,num1=0,num2=0):
|
| 1100 |
print(type(img))
|
|
@@ -1127,23 +1129,23 @@ def PickColorContours(plan,dp,img,radioButton,radioButton1, color,color1,color2,
|
|
| 1127 |
else:
|
| 1128 |
if radioButton=="Measure Full Image":
|
| 1129 |
if radioButton1=='Area':
|
| 1130 |
-
Dictionary, imgPerimeter1,image_new1 =MainFunc(plan,green2,img,dp,finalColorArray,0,num1,num2,'area')
|
| 1131 |
else:
|
| 1132 |
-
Dictionary, imgPerimeter1,image_new1 =MainFunc(plan,green2,img,dp,finalColorArray,0,num1,num2,'perimeter')
|
| 1133 |
|
| 1134 |
else:
|
| 1135 |
if radioButton1=='Area':
|
| 1136 |
-
Dictionary, imgPerimeter1,image_new1 =MainFunc(plan,green2,img,dp,finalColorArray,220,num1,num2,'area')
|
| 1137 |
else:
|
| 1138 |
-
Dictionary, imgPerimeter1,image_new1 =MainFunc(plan,green2,img,dp,finalColorArray,220,num1,num2,'perimeter')
|
| 1139 |
|
| 1140 |
Dictionary=Dictionary.T
|
| 1141 |
# s=s.to_html()
|
| 1142 |
# Dictionary.to_excel("output.xlsx")
|
| 1143 |
|
| 1144 |
if (radioButton1=='Area'):
|
| 1145 |
-
return image_new1,Dictionary #,str(rgbValue),
|
| 1146 |
-
return imgPerimeter1,Dictionary
|
| 1147 |
|
| 1148 |
''' General measurement function'''
|
| 1149 |
def getMeasurement(plan,SaveOP,check1, dp,in2,in3,in4,in5,in6,in7,in8,in9,in10,in11,in12,num1=0,num2=0):
|
|
@@ -1274,7 +1276,7 @@ with gr.Blocks(css="#search {background: orangered}") as mainBlock:
|
|
| 1274 |
out1=gr.Image(label="Image", type="pil", image_mode="RGBA")
|
| 1275 |
out2=gr.Dataframe(label='Dictionary', interactive=True) # row_count = (5, "fixed")
|
| 1276 |
# out3=gr.HTML( elem_id="coords", visible=True)
|
| 1277 |
-
|
| 1278 |
|
| 1279 |
buttonSaveDf=gr.Button("Save dataframe")
|
| 1280 |
|
|
@@ -1285,7 +1287,7 @@ with gr.Blocks(css="#search {background: orangered}") as mainBlock:
|
|
| 1285 |
# btn1.click(fn=PickColorContours, inputs=[dp,in1,in2,in3,in4,in5,in6,in7,in8,in9,in10,in11], outputs=out1)
|
| 1286 |
#secoond part
|
| 1287 |
# btn.click(fn=PickColorContours, inputs=[dp,in2,in3,in4,in5,in6,in7,in8,in9,in10,in11,num1,num2], outputs=outputs1)
|
| 1288 |
-
btn.click(fn=getMeasurement, inputs=[ drop, check,check1 ,dp,in2,in3,in4,in5,in6,in7,in8,in9,in10,in11,in12,num1,num2],outputs=[out1,out2])
|
| 1289 |
project.change(fn=update_dropdown, inputs=[project], outputs=drop)
|
| 1290 |
|
| 1291 |
mainBlock.launch(debug=True,enable_queue=True)
|
|
|
|
| 938 |
dropdownValues.append(*dictVal)
|
| 939 |
print(dropdownValues)
|
| 940 |
worksheet.update_col(index=1, values=dropdownValues)
|
| 941 |
+
|
| 942 |
return dropdownValues
|
| 943 |
|
| 944 |
|
|
|
|
| 1067 |
res = spreadsheet_service.spreadsheets().batchUpdate(spreadsheetId=spreadsheetId, body=body).execute()
|
| 1068 |
spreadsheet_url = "https://docs.google.com/spreadsheets/d/%s" % spreadsheetId
|
| 1069 |
print(spreadsheet_url)
|
| 1070 |
+
# return gr.HTML( """Click <a href=%s> on this Google Sheet </a> to continue to the Legend.""" %spreadsheet_url)
|
| 1071 |
|
| 1072 |
+
return gc,spreadsheet_service,spreadsheetId , spreadsheet_url
|
| 1073 |
|
| 1074 |
|
| 1075 |
|
| 1076 |
def MainFunc(plan,green2,img,dp,finalColorArray,number,num1,num2,flag):
|
| 1077 |
|
| 1078 |
imgPerimeter1,image_new1,Df2,colorsUsed=drawAllContours(plan,green2,img,number,finalColorArray,num1,num2,flag)
|
| 1079 |
+
gc,spreadsheet_service,spreadsheetId ,spreadsheet_url =legendGoogleSheets(plan,Df2,colorsUsed)
|
| 1080 |
# x = path.split("/")
|
| 1081 |
# x=x.pop()
|
| 1082 |
Df2=Df2.T
|
|
|
|
| 1096 |
|
| 1097 |
# display(Df2)
|
| 1098 |
|
| 1099 |
+
return Df2, imgPerimeter1,image_new1 , spreadsheet_url
|
| 1100 |
|
| 1101 |
def PickColorContours(plan,dp,img,radioButton,radioButton1, color,color1,color2,color3,color4,color5,color6,color7,color8,num1=0,num2=0):
|
| 1102 |
print(type(img))
|
|
|
|
| 1129 |
else:
|
| 1130 |
if radioButton=="Measure Full Image":
|
| 1131 |
if radioButton1=='Area':
|
| 1132 |
+
Dictionary, imgPerimeter1,image_new1 ,spreadsheet_url =MainFunc(plan,green2,img,dp,finalColorArray,0,num1,num2,'area')
|
| 1133 |
else:
|
| 1134 |
+
Dictionary, imgPerimeter1,image_new1 ,spreadsheet_url=MainFunc(plan,green2,img,dp,finalColorArray,0,num1,num2,'perimeter')
|
| 1135 |
|
| 1136 |
else:
|
| 1137 |
if radioButton1=='Area':
|
| 1138 |
+
Dictionary, imgPerimeter1,image_new1 ,spreadsheet_url=MainFunc(plan,green2,img,dp,finalColorArray,220,num1,num2,'area')
|
| 1139 |
else:
|
| 1140 |
+
Dictionary, imgPerimeter1,image_new1 ,spreadsheet_url=MainFunc(plan,green2,img,dp,finalColorArray,220,num1,num2,'perimeter')
|
| 1141 |
|
| 1142 |
Dictionary=Dictionary.T
|
| 1143 |
# s=s.to_html()
|
| 1144 |
# Dictionary.to_excel("output.xlsx")
|
| 1145 |
|
| 1146 |
if (radioButton1=='Area'):
|
| 1147 |
+
return image_new1,Dictionary ,spreadsheet_url#,str(rgbValue),
|
| 1148 |
+
return imgPerimeter1,Dictionary ,spreadsheet_url
|
| 1149 |
|
| 1150 |
''' General measurement function'''
|
| 1151 |
def getMeasurement(plan,SaveOP,check1, dp,in2,in3,in4,in5,in6,in7,in8,in9,in10,in11,in12,num1=0,num2=0):
|
|
|
|
| 1276 |
out1=gr.Image(label="Image", type="pil", image_mode="RGBA")
|
| 1277 |
out2=gr.Dataframe(label='Dictionary', interactive=True) # row_count = (5, "fixed")
|
| 1278 |
# out3=gr.HTML( elem_id="coords", visible=True)
|
| 1279 |
+
out3=gr.HTML( """Click <a href=%s> on this Google Sheet </a> to continue to the Legend.""" )
|
| 1280 |
|
| 1281 |
buttonSaveDf=gr.Button("Save dataframe")
|
| 1282 |
|
|
|
|
| 1287 |
# btn1.click(fn=PickColorContours, inputs=[dp,in1,in2,in3,in4,in5,in6,in7,in8,in9,in10,in11], outputs=out1)
|
| 1288 |
#secoond part
|
| 1289 |
# btn.click(fn=PickColorContours, inputs=[dp,in2,in3,in4,in5,in6,in7,in8,in9,in10,in11,num1,num2], outputs=outputs1)
|
| 1290 |
+
btn.click(fn=getMeasurement, inputs=[ drop, check,check1 ,dp,in2,in3,in4,in5,in6,in7,in8,in9,in10,in11,in12,num1,num2],outputs=[out1,out2,out3])
|
| 1291 |
project.change(fn=update_dropdown, inputs=[project], outputs=drop)
|
| 1292 |
|
| 1293 |
mainBlock.launch(debug=True,enable_queue=True)
|