Ephraimmm commited on
Commit
2aa013d
·
verified ·
1 Parent(s): 42eaf52

Update app.py

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