yappeizhen commited on
Commit
1b9dc89
1 Parent(s): fb7b12f

feat: firestore setup

Browse files
Files changed (5) hide show
  1. .env.example +1 -0
  2. .gitignore +2 -0
  3. README.md +10 -0
  4. app.py +16 -0
  5. requirements.txt +2 -0
.env.example ADDED
@@ -0,0 +1 @@
 
 
1
+ GOOGLE_APPLICATION_CREDENTIALS=
.gitignore ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ .env
2
+ limkopi-9d239-*.json
README.md CHANGED
@@ -36,10 +36,20 @@ GIT_LFS_SKIP_SMUDGE=1
36
 
37
  ### 2. Environment Setup
38
 
 
 
39
  ```sh
40
  python3 -m venv venv
41
  ```
42
 
 
 
 
 
 
 
 
 
43
  #### Activate the virtual environment
44
 
45
  - **On Windows**
 
36
 
37
  ### 2. Environment Setup
38
 
39
+ ### Create virtual environment
40
+
41
  ```sh
42
  python3 -m venv venv
43
  ```
44
 
45
+ ### Set environment variables
46
+
47
+ Fill in the corresponding credentials accordingly in `.env`
48
+
49
+ ```sh
50
+ cp .env.example .env
51
+ ```
52
+
53
  #### Activate the virtual environment
54
 
55
  - **On Windows**
app.py CHANGED
@@ -1,7 +1,23 @@
 
 
 
1
  import gradio as gr
2
  import whisper
3
  from transformers import pipeline
 
 
4
 
 
 
 
 
 
 
 
 
 
 
 
5
  model = whisper.load_model("base")
6
  sentiment_analysis = pipeline("sentiment-analysis", framework="pt", model="SamLowe/roberta-base-go_emotions")
7
 
 
1
+ import os
2
+ import json
3
+ from google.cloud import firestore
4
  import gradio as gr
5
  import whisper
6
  from transformers import pipeline
7
+ from dotenv import load_dotenv
8
+ import base64
9
 
10
+ # Load google cloud credentials
11
+ load_dotenv()
12
+ base64_credentials = os.environ.get('GOOGLE_APPLICATION_CREDENTIALS')
13
+ decoded_credentials = base64.b64decode(base64_credentials).decode()
14
+ credentials_json = json.loads(decoded_credentials)
15
+ db = firestore.Client.from_service_account_info(credentials_json)
16
+
17
+ collection_ref = db.collection('Users')
18
+ docs = collection_ref.stream()
19
+
20
+ # Load model
21
  model = whisper.load_model("base")
22
  sentiment_analysis = pipeline("sentiment-analysis", framework="pt", model="SamLowe/roberta-base-go_emotions")
23
 
requirements.txt CHANGED
@@ -4,3 +4,5 @@ gradio
4
  torch
5
  torchaudio
6
  torchvision
 
 
 
4
  torch
5
  torchaudio
6
  torchvision
7
+ google-cloud-firestore
8
+ python-dotenv