Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -27,6 +27,50 @@ technologies_df = pd.DataFrame()
|
|
| 27 |
technology_embeddings = None # Will store pre-computed embeddings for descriptions
|
| 28 |
model = None
|
| 29 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
# --- Load Data and Model (Load once at startup) ---
|
| 31 |
def load_data_and_model():
|
| 32 |
global categories_data, category_names, category_embeddings
|
|
|
|
| 27 |
technology_embeddings = None # Will store pre-computed embeddings for descriptions
|
| 28 |
model = None
|
| 29 |
|
| 30 |
+
|
| 31 |
+
###- GOOGLE DRIVE API
|
| 32 |
+
|
| 33 |
+
from google.oauth2 import service_account
|
| 34 |
+
from googleapiclient.discovery import build
|
| 35 |
+
from googleapiclient.http import MediaIoBaseDownload, MediaIoBaseUpload
|
| 36 |
+
|
| 37 |
+
# Environment variables
|
| 38 |
+
FOLDER_ID = os.getenv("FOLDER_ID")
|
| 39 |
+
GOOGLE_CREDENTIALS = os.environ.get("GOOGLE_CREDENTIALS")
|
| 40 |
+
|
| 41 |
+
def create_new_file_in_drive(username, dataframe_to_upload, credentials_json, folder_id):
|
| 42 |
+
"""Crée un nouveau fichier CSV dans Google Drive à partir d'un DataFrame Pandas."""
|
| 43 |
+
|
| 44 |
+
creds_dict = json.loads(credentials_json)
|
| 45 |
+
|
| 46 |
+
# Charger les informations d'identification du compte de service
|
| 47 |
+
creds = service_account.Credentials.from_service_account_info(creds_dict)
|
| 48 |
+
|
| 49 |
+
# Construire le service API Drive
|
| 50 |
+
service = build('drive', 'v3', credentials=creds)
|
| 51 |
+
|
| 52 |
+
# Convertir le DataFrame en fichier CSV en mémoire
|
| 53 |
+
csv_buffer = io.BytesIO()
|
| 54 |
+
dataframe_to_upload.to_csv(csv_buffer, index=False, sep=';', encoding='utf-8')
|
| 55 |
+
csv_buffer.seek(0)
|
| 56 |
+
|
| 57 |
+
# Créer les métadonnées du fichier
|
| 58 |
+
filename = f"rating-results-{username}.csv"
|
| 59 |
+
file_metadata = {
|
| 60 |
+
'name': filename,
|
| 61 |
+
'parents': [folder_id]
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
# Télécharger le fichier CSV sur Google Drive
|
| 65 |
+
media = MediaIoBaseUpload(csv_buffer, mimetype='text/csv', resumable=True)
|
| 66 |
+
file = service.files().create(body=file_metadata, media_body=media, fields='id').execute()
|
| 67 |
+
|
| 68 |
+
print(f"File '{filename}' created successfully.")
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
###-
|
| 72 |
+
|
| 73 |
+
|
| 74 |
# --- Load Data and Model (Load once at startup) ---
|
| 75 |
def load_data_and_model():
|
| 76 |
global categories_data, category_names, category_embeddings
|