nmariotto commited on
Commit
a6bcf91
·
verified ·
1 Parent(s): 0cacf7b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -1
app.py CHANGED
@@ -28,7 +28,7 @@ dpi_value = 300
28
  with st.expander("⚙️ Advanced Settings", expanded=True):
29
  model.confidence = st.slider("Model Confidence (%)", 20, 100, 80)
30
 
31
- # 📁 Setup Google Drive and Sheets
32
  scope = ["https://www.googleapis.com/auth/drive", "https://www.googleapis.com/auth/spreadsheets"]
33
  credentials_dict = json.loads(st.secrets["gcp_service_account"] )
34
  credentials = service_account.Credentials.from_service_account_info(credentials_dict, scopes=scope)
@@ -36,6 +36,17 @@ drive_service = build("drive", "v3", credentials=credentials)
36
  sheets_client = gspread.authorize(credentials)
37
  sheet = sheets_client.open_by_url(st.secrets["feedback_sheet_url"]).sheet1
38
 
 
 
 
 
 
 
 
 
 
 
 
39
  # 📌 Helper Functions
40
  def calculate_polygon_area(points):
41
  polygon = Polygon([(p['x'], p['y']) for p in points])
 
28
  with st.expander("⚙️ Advanced Settings", expanded=True):
29
  model.confidence = st.slider("Model Confidence (%)", 20, 100, 80)
30
 
31
+ # 📁 Setup Google Drive and Sheets (seção aprimorada)
32
  scope = ["https://www.googleapis.com/auth/drive", "https://www.googleapis.com/auth/spreadsheets"]
33
  credentials_dict = json.loads(st.secrets["gcp_service_account"] )
34
  credentials = service_account.Credentials.from_service_account_info(credentials_dict, scopes=scope)
 
36
  sheets_client = gspread.authorize(credentials)
37
  sheet = sheets_client.open_by_url(st.secrets["feedback_sheet_url"]).sheet1
38
 
39
+ # Verifica e insere o cabeçalho se a planilha estiver vazia
40
+ header = ["Image", "Evaluation", "Observation"]
41
+ try:
42
+ # get_all_records() falha se o cabeçalho não existir ou a planilha estiver vazia
43
+ sheet.get_all_records()
44
+ except gspread.exceptions.GSpreadException:
45
+ # Se falhar, verificamos se a primeira linha está vazia para decidir se inserimos o cabeçalho
46
+ if not sheet.row_values(1):
47
+ sheet.insert_row(header, 1)
48
+
49
+
50
  # 📌 Helper Functions
51
  def calculate_polygon_area(points):
52
  polygon = Polygon([(p['x'], p['y']) for p in points])