Spaces:
Runtime error
Runtime error
update backend functions
Browse files
app.py
CHANGED
@@ -1,18 +1,16 @@
|
|
1 |
import gradio as gr
|
2 |
import os
|
3 |
-
import
|
4 |
-
|
5 |
-
from utils import make_invisible, make_visible
|
6 |
from backend_functions import get_answer, init_greeting, export_dataframe
|
7 |
|
8 |
from dotenv import load_dotenv
|
9 |
load_dotenv()
|
10 |
|
11 |
-
|
|
|
12 |
|
13 |
with gr.Blocks() as main_app:
|
14 |
-
|
15 |
-
times_functions = gr.State([[], [], []])
|
16 |
|
17 |
with gr.Tab('Chatbot'):
|
18 |
user_id = gr.State('') # id used to find the chat into the database
|
|
|
1 |
import gradio as gr
|
2 |
import os
|
3 |
+
from gcp import download_credentials
|
4 |
+
from utils import make_invisible, make_visible, create_folders
|
|
|
5 |
from backend_functions import get_answer, init_greeting, export_dataframe
|
6 |
|
7 |
from dotenv import load_dotenv
|
8 |
load_dotenv()
|
9 |
|
10 |
+
download_credentials()
|
11 |
+
create_folders()
|
12 |
|
13 |
with gr.Blocks() as main_app:
|
|
|
|
|
14 |
|
15 |
with gr.Tab('Chatbot'):
|
16 |
user_id = gr.State('') # id used to find the chat into the database
|
backend_functions.py
CHANGED
@@ -9,15 +9,15 @@ import uuid
|
|
9 |
import re
|
10 |
import pandas as pd
|
11 |
import tensorflow as tf
|
12 |
-
from utils import create_folders
|
13 |
from google.cloud import storage
|
14 |
from elevenlabs.client import ElevenLabs, AsyncElevenLabs
|
15 |
from elevenlabs import play, save, Voice, stream
|
16 |
from pymongo.mongo_client import MongoClient
|
17 |
-
from gcp import download_credentials
|
18 |
from dotenv import load_dotenv
|
19 |
load_dotenv()
|
20 |
|
|
|
|
|
21 |
OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
|
22 |
MODEL_OPENAI = os.getenv("MODEL_OPENAI")
|
23 |
|
@@ -37,6 +37,8 @@ IMG_XAVY = os.getenv("IMG_XAVY")
|
|
37 |
CREDENTIALS_GCP = os.getenv("GOOGLE_APPLICATION_CREDENTIALS")
|
38 |
NAME_BUCKET = os.getenv("NAME_BUCKET")
|
39 |
|
|
|
|
|
40 |
|
41 |
# Chat
|
42 |
openai_client = OpenAI(api_key=OPENAI_API_KEY)
|
@@ -249,8 +251,6 @@ def _create_clean_message(text: str):
|
|
249 |
def _create_audio(clean_text: str):
|
250 |
|
251 |
if tf.test.is_gpu_available():
|
252 |
-
download_credentials()
|
253 |
-
create_folders()
|
254 |
STORAGE_CLIENT = storage.Client.from_service_account_json(CREDENTIALS_GCP)
|
255 |
|
256 |
unique_id = str(uuid.uuid4())
|
@@ -289,8 +289,6 @@ def _create_audio(clean_text: str):
|
|
289 |
except Exception as e:
|
290 |
print(e)
|
291 |
else:
|
292 |
-
download_credentials()
|
293 |
-
create_folders()
|
294 |
STORAGE_CLIENT = storage.Client.from_service_account_json(CREDENTIALS_GCP)
|
295 |
|
296 |
unique_id = str(uuid.uuid4())
|
|
|
9 |
import re
|
10 |
import pandas as pd
|
11 |
import tensorflow as tf
|
|
|
12 |
from google.cloud import storage
|
13 |
from elevenlabs.client import ElevenLabs, AsyncElevenLabs
|
14 |
from elevenlabs import play, save, Voice, stream
|
15 |
from pymongo.mongo_client import MongoClient
|
|
|
16 |
from dotenv import load_dotenv
|
17 |
load_dotenv()
|
18 |
|
19 |
+
GEMINI_API_KEY = os.getenv("GEMINI_API_KEY")
|
20 |
+
|
21 |
OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
|
22 |
MODEL_OPENAI = os.getenv("MODEL_OPENAI")
|
23 |
|
|
|
37 |
CREDENTIALS_GCP = os.getenv("GOOGLE_APPLICATION_CREDENTIALS")
|
38 |
NAME_BUCKET = os.getenv("NAME_BUCKET")
|
39 |
|
40 |
+
# Gemini
|
41 |
+
genai.configure(api_key=GEMINI_API_KEY)
|
42 |
|
43 |
# Chat
|
44 |
openai_client = OpenAI(api_key=OPENAI_API_KEY)
|
|
|
251 |
def _create_audio(clean_text: str):
|
252 |
|
253 |
if tf.test.is_gpu_available():
|
|
|
|
|
254 |
STORAGE_CLIENT = storage.Client.from_service_account_json(CREDENTIALS_GCP)
|
255 |
|
256 |
unique_id = str(uuid.uuid4())
|
|
|
289 |
except Exception as e:
|
290 |
print(e)
|
291 |
else:
|
|
|
|
|
292 |
STORAGE_CLIENT = storage.Client.from_service_account_json(CREDENTIALS_GCP)
|
293 |
|
294 |
unique_id = str(uuid.uuid4())
|
gcp.py
CHANGED
@@ -4,6 +4,7 @@ from datetime import timedelta
|
|
4 |
from google.cloud import storage
|
5 |
from huggingface_hub import hf_hub_download
|
6 |
from google.cloud.storage import transfer_manager
|
|
|
7 |
from dotenv import load_dotenv
|
8 |
load_dotenv()
|
9 |
|
@@ -14,15 +15,17 @@ def download_credentials() -> None:
|
|
14 |
"""
|
15 |
Downloads the GCP credentials from Hugging Face Hub
|
16 |
"""
|
17 |
-
assets_dir = 'assets'
|
18 |
credentials_file = os.path.join(assets_dir, "credentials.json")
|
|
|
19 |
|
20 |
# Verificar si la carpeta 'assets' existe y crearla si no
|
21 |
os.makedirs(assets_dir, exist_ok=True)
|
22 |
|
23 |
# Verificar si el archivo 'credentials.json' ya existe en la carpeta 'assets'
|
24 |
if not os.path.isfile(credentials_file):
|
|
|
25 |
hf_hub_download(
|
26 |
repo_id=REPO_HUGGING, repo_type='dataset', filename="credentials.json",
|
27 |
token=HUB_TOKEN, local_dir=assets_dir
|
28 |
-
)
|
|
|
4 |
from google.cloud import storage
|
5 |
from huggingface_hub import hf_hub_download
|
6 |
from google.cloud.storage import transfer_manager
|
7 |
+
|
8 |
from dotenv import load_dotenv
|
9 |
load_dotenv()
|
10 |
|
|
|
15 |
"""
|
16 |
Downloads the GCP credentials from Hugging Face Hub
|
17 |
"""
|
18 |
+
assets_dir = './assets'
|
19 |
credentials_file = os.path.join(assets_dir, "credentials.json")
|
20 |
+
print(credentials_file)
|
21 |
|
22 |
# Verificar si la carpeta 'assets' existe y crearla si no
|
23 |
os.makedirs(assets_dir, exist_ok=True)
|
24 |
|
25 |
# Verificar si el archivo 'credentials.json' ya existe en la carpeta 'assets'
|
26 |
if not os.path.isfile(credentials_file):
|
27 |
+
print("No habian credenciales")
|
28 |
hf_hub_download(
|
29 |
repo_id=REPO_HUGGING, repo_type='dataset', filename="credentials.json",
|
30 |
token=HUB_TOKEN, local_dir=assets_dir
|
31 |
+
)
|
utils.py
CHANGED
@@ -19,15 +19,12 @@ def create_folders():
|
|
19 |
"""
|
20 |
Creates 'audios' and 'videos' directories if they do not exist
|
21 |
"""
|
22 |
-
audio_dir = 'audios'
|
23 |
-
video_dir = 'videos'
|
24 |
-
times_dir = 'csv_times'
|
25 |
|
26 |
-
|
27 |
-
os.makedirs(audio_dir)
|
28 |
|
29 |
-
|
30 |
-
os.makedirs(video_dir)
|
31 |
|
32 |
-
|
33 |
-
os.makedirs(times_dir)
|
|
|
19 |
"""
|
20 |
Creates 'audios' and 'videos' directories if they do not exist
|
21 |
"""
|
22 |
+
audio_dir = './audios'
|
23 |
+
video_dir = './videos'
|
24 |
+
times_dir = './csv_times'
|
25 |
|
26 |
+
os.makedirs(audio_dir, exist_ok=True)
|
|
|
27 |
|
28 |
+
os.makedirs(video_dir, exist_ok=True)
|
|
|
29 |
|
30 |
+
os.makedirs(times_dir, exist_ok=True)
|
|