Update app.py
Browse files
app.py
CHANGED
|
@@ -8,19 +8,34 @@ import torch
|
|
| 8 |
from transformers import pipeline
|
| 9 |
import librosa
|
| 10 |
import gradio as gr
|
| 11 |
-
import requests
|
| 12 |
|
| 13 |
# Directory to store/load cookies
|
| 14 |
cookie_path_dir = "./cookies/"
|
| 15 |
-
os.
|
| 16 |
|
| 17 |
-
# Load pre-saved cookies
|
| 18 |
try:
|
| 19 |
-
print("Attempting to load cookies from:",
|
| 20 |
-
|
| 21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
except Exception as e:
|
| 23 |
-
print(f"Failed to
|
|
|
|
|
|
|
| 24 |
sys.exit(1)
|
| 25 |
|
| 26 |
# Model and device configuration for Whisper transcription
|
|
|
|
| 8 |
from transformers import pipeline
|
| 9 |
import librosa
|
| 10 |
import gradio as gr
|
|
|
|
| 11 |
|
| 12 |
# Directory to store/load cookies
|
| 13 |
cookie_path_dir = "./cookies/"
|
| 14 |
+
cookie_file_path = os.path.join(cookie_path_dir, "cookies_snapshot.json") # Default file name used by hugchat
|
| 15 |
|
| 16 |
+
# Load pre-saved cookies
|
| 17 |
try:
|
| 18 |
+
print("Attempting to load cookies from:", cookie_file_path)
|
| 19 |
+
if not os.path.exists(cookie_file_path):
|
| 20 |
+
# If cookies don't exist, attempt to generate them (for local testing; remove in Spaces)
|
| 21 |
+
EMAIL = os.environ.get("EMAIL", "[email protected]") # Fallback for local testing
|
| 22 |
+
PASSWD = os.environ.get("PASSWORD", "e.AKsv$3Q4i4KcX") # Fallback for local testing
|
| 23 |
+
os.makedirs(cookie_path_dir, exist_ok=True)
|
| 24 |
+
sign = Login(EMAIL, PASSWD)
|
| 25 |
+
cookies = sign.login(cookie_dir_path=cookie_path_dir, save_cookies=True)
|
| 26 |
+
print("Generated new cookies since none were found.")
|
| 27 |
+
else:
|
| 28 |
+
# Load existing cookies
|
| 29 |
+
with open(cookie_file_path, "r") as f:
|
| 30 |
+
cookies = json.load(f) # Load the cookie dictionary
|
| 31 |
+
print("Cookies loaded from file.")
|
| 32 |
+
|
| 33 |
+
chatbot = hugchat.ChatBot(cookies=cookies) # Pass cookies directly
|
| 34 |
+
print("ChatBot initialized successfully.")
|
| 35 |
except Exception as e:
|
| 36 |
+
print(f"Failed to initialize ChatBot: {str(e)}")
|
| 37 |
+
import traceback
|
| 38 |
+
traceback.print_exc()
|
| 39 |
sys.exit(1)
|
| 40 |
|
| 41 |
# Model and device configuration for Whisper transcription
|