maliahson commited on
Commit
b8a67e0
·
verified ·
1 Parent(s): 925d48c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -7
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.makedirs(cookie_path_dir, exist_ok=True)
16
 
17
- # Load pre-saved cookies instead of logging in
18
  try:
19
- print("Attempting to load cookies from:", cookie_path_dir)
20
- chatbot = hugchat.ChatBot(cookie_path_dir=cookie_path_dir)
21
- print("Cookies loaded successfully.")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22
  except Exception as e:
23
- print(f"Failed to load cookies: {str(e)}")
 
 
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