Update app.py
Browse files
app.py
CHANGED
|
@@ -10,7 +10,7 @@ from shapely.geometry import Polygon
|
|
| 10 |
from PIL import Image
|
| 11 |
from io import BytesIO
|
| 12 |
from concurrent.futures import ThreadPoolExecutor
|
| 13 |
-
from google.oauth2 import
|
| 14 |
from googleapiclient.discovery import build
|
| 15 |
from googleapiclient.http import MediaIoBaseUpload
|
| 16 |
import gspread
|
|
@@ -28,10 +28,16 @@ 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 e Sheets
|
| 32 |
scope = ["https://www.googleapis.com/auth/drive", "https://www.googleapis.com/auth/spreadsheets"]
|
| 33 |
-
|
| 34 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
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
|
|
@@ -222,7 +228,7 @@ if results:
|
|
| 222 |
sheet.append_row(row)
|
| 223 |
|
| 224 |
if avaliacao in ["Acceptable", "Bad", "No segmentation"]:
|
| 225 |
-
sufixo = "aceitavel" if avaliacao == "Acceptable" else "ruim" if avaliacao == "Bad" else "
|
| 226 |
parent_folder = find_or_create_folder("Feedback Segmentacoes")
|
| 227 |
subfolder = find_or_create_folder(imagem_escolhida.replace(".png", ""), parent_folder)
|
| 228 |
|
|
@@ -245,4 +251,4 @@ if results:
|
|
| 245 |
upload_to_drive(buffer, f"{nome}_{sufixo}.png", subfolder)
|
| 246 |
break
|
| 247 |
|
| 248 |
-
st.success("✅ Feedback saved successfully!")
|
|
|
|
| 10 |
from PIL import Image
|
| 11 |
from io import BytesIO
|
| 12 |
from concurrent.futures import ThreadPoolExecutor
|
| 13 |
+
from google.oauth2.credentials import Credentials
|
| 14 |
from googleapiclient.discovery import build
|
| 15 |
from googleapiclient.http import MediaIoBaseUpload
|
| 16 |
import gspread
|
|
|
|
| 28 |
with st.expander("⚙️ Advanced Settings", expanded=True):
|
| 29 |
model.confidence = st.slider("Model Confidence (%)", 20, 100, 80)
|
| 30 |
|
| 31 |
+
# 📁 Setup Google Drive e Sheets com OAuth 2.0
|
| 32 |
scope = ["https://www.googleapis.com/auth/drive", "https://www.googleapis.com/auth/spreadsheets"]
|
| 33 |
+
credentials = Credentials(
|
| 34 |
+
token=None,
|
| 35 |
+
refresh_token=st.secrets["GOOGLE_DRIVE_REFRESH_TOKEN"],
|
| 36 |
+
token_uri="https://oauth2.googleapis.com/token",
|
| 37 |
+
client_id=st.secrets["GOOGLE_DRIVE_CLIENT_ID"],
|
| 38 |
+
client_secret=st.secrets["GOOGLE_DRIVE_CLIENT_SECRET"],
|
| 39 |
+
scopes=scope
|
| 40 |
+
)
|
| 41 |
drive_service = build("drive", "v3", credentials=credentials)
|
| 42 |
sheets_client = gspread.authorize(credentials)
|
| 43 |
sheet = sheets_client.open_by_url(st.secrets["feedback_sheet_url"]).sheet1
|
|
|
|
| 228 |
sheet.append_row(row)
|
| 229 |
|
| 230 |
if avaliacao in ["Acceptable", "Bad", "No segmentation"]:
|
| 231 |
+
sufixo = "aceitavel" if avaliacao == "Acceptable" else "ruim" if avaliacao == "Bad" else "No segmentation"
|
| 232 |
parent_folder = find_or_create_folder("Feedback Segmentacoes")
|
| 233 |
subfolder = find_or_create_folder(imagem_escolhida.replace(".png", ""), parent_folder)
|
| 234 |
|
|
|
|
| 251 |
upload_to_drive(buffer, f"{nome}_{sufixo}.png", subfolder)
|
| 252 |
break
|
| 253 |
|
| 254 |
+
st.success("✅ Feedback saved successfully!")
|