Ephraimmm commited on
Commit
5eb5724
·
verified ·
1 Parent(s): 1e3b610

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -6
app.py CHANGED
@@ -11,15 +11,36 @@ from openai import OpenAI
11
  openai.api_key = os.getenv('OPENAI_API_KEY')
12
  openai = OpenAI(api_key = openai.api_key)
13
 
14
- service_account_file_path = os.getenv("GOOGLE_SERVICE_ACCOUNT_FILE")
15
 
16
  class GPTDriveIntegration:
17
  def __init__(self):
18
- # Initialize Google Drive API
19
- self.credentials = service_account.Credentials.from_service_account_file(
20
- os.getenv('GOOGLE_SERVICE_ACCOUNT_FILE'),
21
- scopes=['https://www.googleapis.com/auth/drive.readonly']
22
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23
  self.drive_service = build('drive', 'v3', credentials=self.credentials)
24
 
25
  # Initialize OpenAI
 
11
  openai.api_key = os.getenv('OPENAI_API_KEY')
12
  openai = OpenAI(api_key = openai.api_key)
13
 
 
14
 
15
  class GPTDriveIntegration:
16
  def __init__(self):
17
+ # Download the credentials file from Hugging Face
18
+ credentials_url = "https://huggingface.co/spaces/Ephraimmm/studybuddy/resolve/main/rag-system-463320-f292991d0516.json"
19
+
20
+ try:
21
+ # Download the file
22
+ response = requests.get(credentials_url)
23
+ response.raise_for_status() # Raise an exception for bad status codes
24
+
25
+ # Create a temporary file to store the credentials
26
+ with tempfile.NamedTemporaryFile(mode='w', suffix='.json', delete=False) as temp_file:
27
+ json.dump(response.json(), temp_file)
28
+ temp_credentials_path = temp_file.name
29
+
30
+ # Initialize Google Drive API with the temporary file
31
+ self.credentials = service_account.Credentials.from_service_account_file(
32
+ temp_credentials_path,
33
+ scopes=['https://www.googleapis.com/auth/drive.readonly']
34
+ )
35
+
36
+ # Clean up the temporary file
37
+ os.unlink(temp_credentials_path)
38
+
39
+ except requests.RequestException as e:
40
+ raise Exception(f"Failed to download credentials file: {e}")
41
+ except json.JSONDecodeError as e:
42
+ raise Exception(f"Invalid JSON in credentials file: {e}")
43
+
44
  self.drive_service = build('drive', 'v3', credentials=self.credentials)
45
 
46
  # Initialize OpenAI