Spaces:
Runtime error
Runtime error
adding logs instead of print
Browse files- app.py +16 -16
- google_manager/auth.py +1 -0
- google_manager/docs.py +6 -5
- google_manager/drive.py +9 -4
- gpt_summary.py +3 -5
app.py
CHANGED
|
@@ -40,15 +40,15 @@ async def authorize(request: Request):
|
|
| 40 |
)
|
| 41 |
|
| 42 |
# for dev
|
| 43 |
-
|
| 44 |
# for production
|
| 45 |
-
flow.redirect_uri = (
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
)
|
| 52 |
|
| 53 |
authorization_url, state = flow.authorization_url(
|
| 54 |
access_type="offline",
|
|
@@ -66,15 +66,15 @@ async def auth_callback(request: Request):
|
|
| 66 |
"credentials.json", scopes=SCOPES, state=state
|
| 67 |
)
|
| 68 |
# for dev
|
| 69 |
-
|
| 70 |
# for production
|
| 71 |
-
flow.redirect_uri = (
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
)
|
| 78 |
|
| 79 |
# Use the authorization server's response to fetch the OAuth 2.0 tokens.
|
| 80 |
authorization_response = str(request.url)
|
|
|
|
| 40 |
)
|
| 41 |
|
| 42 |
# for dev
|
| 43 |
+
flow.redirect_uri = "http://127.0.0.1:8000/auth_callback"
|
| 44 |
# for production
|
| 45 |
+
# flow.redirect_uri = (
|
| 46 |
+
# request.url.scheme
|
| 47 |
+
# + "://"
|
| 48 |
+
# + request.url.hostname
|
| 49 |
+
# + (":" + str(request.url.port) if request.url.port else "")
|
| 50 |
+
# + app.url_path_for("auth_callback")
|
| 51 |
+
# )
|
| 52 |
|
| 53 |
authorization_url, state = flow.authorization_url(
|
| 54 |
access_type="offline",
|
|
|
|
| 66 |
"credentials.json", scopes=SCOPES, state=state
|
| 67 |
)
|
| 68 |
# for dev
|
| 69 |
+
flow.redirect_uri = "http://127.0.0.1:8000/auth_callback"
|
| 70 |
# for production
|
| 71 |
+
# flow.redirect_uri = (
|
| 72 |
+
# request.url.scheme
|
| 73 |
+
# + "://"
|
| 74 |
+
# + request.url.hostname
|
| 75 |
+
# + (":" + str(request.url.port) if request.url.port else "")
|
| 76 |
+
# + app.url_path_for("auth_callback")
|
| 77 |
+
# )
|
| 78 |
|
| 79 |
# Use the authorization server's response to fetch the OAuth 2.0 tokens.
|
| 80 |
authorization_response = str(request.url)
|
google_manager/auth.py
CHANGED
|
@@ -1,4 +1,5 @@
|
|
| 1 |
import google_auth_oauthlib.flow
|
|
|
|
| 2 |
|
| 3 |
|
| 4 |
def get_oauth_url(SCOPES, redirect_url):
|
|
|
|
| 1 |
import google_auth_oauthlib.flow
|
| 2 |
+
import logging
|
| 3 |
|
| 4 |
|
| 5 |
def get_oauth_url(SCOPES, redirect_url):
|
google_manager/docs.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
import datetime
|
| 2 |
from googleapiclient.discovery import build
|
| 3 |
from googleapiclient.errors import HttpError
|
|
|
|
| 4 |
|
| 5 |
|
| 6 |
def save_doc(creds, title, content):
|
|
@@ -11,7 +12,7 @@ def save_doc(creds, title, content):
|
|
| 11 |
title = title
|
| 12 |
body = {"title": title}
|
| 13 |
doc = service.documents().create(body=body).execute()
|
| 14 |
-
|
| 15 |
|
| 16 |
# Get the ID of the new file
|
| 17 |
doc_id = doc["documentId"]
|
|
@@ -26,11 +27,11 @@ def save_doc(creds, title, content):
|
|
| 26 |
.execute()
|
| 27 |
)
|
| 28 |
|
| 29 |
-
|
| 30 |
return result
|
| 31 |
|
| 32 |
except HttpError as err:
|
| 33 |
-
|
| 34 |
|
| 35 |
|
| 36 |
def move_doc(creds, document_id, folder_id):
|
|
@@ -53,12 +54,12 @@ def move_doc(creds, document_id, folder_id):
|
|
| 53 |
.execute()
|
| 54 |
)
|
| 55 |
|
| 56 |
-
|
| 57 |
f'The document with ID {file.get("id")} was moved to the folder with ID {folder_id}.'
|
| 58 |
)
|
| 59 |
|
| 60 |
except HttpError as error:
|
| 61 |
-
|
| 62 |
|
| 63 |
|
| 64 |
def name_doc():
|
|
|
|
| 1 |
import datetime
|
| 2 |
from googleapiclient.discovery import build
|
| 3 |
from googleapiclient.errors import HttpError
|
| 4 |
+
import logging
|
| 5 |
|
| 6 |
|
| 7 |
def save_doc(creds, title, content):
|
|
|
|
| 12 |
title = title
|
| 13 |
body = {"title": title}
|
| 14 |
doc = service.documents().create(body=body).execute()
|
| 15 |
+
logging.info("Created document with title: {0}".format(doc.get("title")))
|
| 16 |
|
| 17 |
# Get the ID of the new file
|
| 18 |
doc_id = doc["documentId"]
|
|
|
|
| 27 |
.execute()
|
| 28 |
)
|
| 29 |
|
| 30 |
+
logging.info(f"A new Google Doc file has been created with ID: {doc_id}")
|
| 31 |
return result
|
| 32 |
|
| 33 |
except HttpError as err:
|
| 34 |
+
logging.info(err)
|
| 35 |
|
| 36 |
|
| 37 |
def move_doc(creds, document_id, folder_id):
|
|
|
|
| 54 |
.execute()
|
| 55 |
)
|
| 56 |
|
| 57 |
+
logging.info(
|
| 58 |
f'The document with ID {file.get("id")} was moved to the folder with ID {folder_id}.'
|
| 59 |
)
|
| 60 |
|
| 61 |
except HttpError as error:
|
| 62 |
+
logging.info(f"An error occurred: {error}")
|
| 63 |
|
| 64 |
|
| 65 |
def name_doc():
|
google_manager/drive.py
CHANGED
|
@@ -1,5 +1,6 @@
|
|
| 1 |
from googleapiclient.discovery import build
|
| 2 |
from googleapiclient.errors import HttpError
|
|
|
|
| 3 |
|
| 4 |
|
| 5 |
def create_folder(creds, folder_name, parent_folder_id=None) -> str:
|
|
@@ -18,10 +19,14 @@ def create_folder(creds, folder_name, parent_folder_id=None) -> str:
|
|
| 18 |
folder = (
|
| 19 |
drive_service.files().create(body=folder_metadata, fields="id").execute()
|
| 20 |
)
|
| 21 |
-
|
|
|
|
|
|
|
| 22 |
return folder["id"]
|
| 23 |
except HttpError as error:
|
| 24 |
-
|
|
|
|
|
|
|
| 25 |
return None
|
| 26 |
|
| 27 |
|
|
@@ -46,14 +51,14 @@ def search_folder(creds, folder_name):
|
|
| 46 |
)
|
| 47 |
for file in response.get("files", []):
|
| 48 |
# Process change
|
| 49 |
-
|
| 50 |
files.extend(response.get("files", []))
|
| 51 |
page_token = response.get("nextPageToken", None)
|
| 52 |
if page_token is None:
|
| 53 |
break
|
| 54 |
|
| 55 |
except HttpError as error:
|
| 56 |
-
|
| 57 |
files = None
|
| 58 |
|
| 59 |
return files
|
|
|
|
| 1 |
from googleapiclient.discovery import build
|
| 2 |
from googleapiclient.errors import HttpError
|
| 3 |
+
import logging
|
| 4 |
|
| 5 |
|
| 6 |
def create_folder(creds, folder_name, parent_folder_id=None) -> str:
|
|
|
|
| 19 |
folder = (
|
| 20 |
drive_service.files().create(body=folder_metadata, fields="id").execute()
|
| 21 |
)
|
| 22 |
+
logging.info(
|
| 23 |
+
f'Folder "{folder_name}" with ID "{folder["id"]}" created successfully'
|
| 24 |
+
)
|
| 25 |
return folder["id"]
|
| 26 |
except HttpError as error:
|
| 27 |
+
logging.info(
|
| 28 |
+
f"An error occurred while creating the Google Drive folder: {error}"
|
| 29 |
+
)
|
| 30 |
return None
|
| 31 |
|
| 32 |
|
|
|
|
| 51 |
)
|
| 52 |
for file in response.get("files", []):
|
| 53 |
# Process change
|
| 54 |
+
logging.info(f'Found file: {file.get("name")}, {file.get("id")}')
|
| 55 |
files.extend(response.get("files", []))
|
| 56 |
page_token = response.get("nextPageToken", None)
|
| 57 |
if page_token is None:
|
| 58 |
break
|
| 59 |
|
| 60 |
except HttpError as error:
|
| 61 |
+
logging.info(f"An error occurred: {error}")
|
| 62 |
files = None
|
| 63 |
|
| 64 |
return files
|
gpt_summary.py
CHANGED
|
@@ -9,7 +9,7 @@ from description import DESCRIPTION
|
|
| 9 |
import gradio as gr
|
| 10 |
from utils import credentials_to_dict
|
| 11 |
import asyncio
|
| 12 |
-
|
| 13 |
|
| 14 |
load_dotenv()
|
| 15 |
|
|
@@ -70,12 +70,10 @@ def transcribe(audio_file):
|
|
| 70 |
|
| 71 |
async def predict(input, request: gr.Request, history=[]):
|
| 72 |
compress(input)
|
| 73 |
-
|
| 74 |
transcription = await asyncio.to_thread(transcribe, input)
|
| 75 |
-
|
| 76 |
-
print("gpt starts")
|
| 77 |
answer = await asyncio.to_thread(chat, transcription)
|
| 78 |
-
print("gpt ends")
|
| 79 |
|
| 80 |
loop = asyncio.get_event_loop()
|
| 81 |
# upload the input/answer to google drive
|
|
|
|
| 9 |
import gradio as gr
|
| 10 |
from utils import credentials_to_dict
|
| 11 |
import asyncio
|
| 12 |
+
import logging
|
| 13 |
|
| 14 |
load_dotenv()
|
| 15 |
|
|
|
|
| 70 |
|
| 71 |
async def predict(input, request: gr.Request, history=[]):
|
| 72 |
compress(input)
|
| 73 |
+
logging.info("Starting HTTP request to Whisper API")
|
| 74 |
transcription = await asyncio.to_thread(transcribe, input)
|
| 75 |
+
logging.info("Starting HTTP request to GPT-3.5 API")
|
|
|
|
| 76 |
answer = await asyncio.to_thread(chat, transcription)
|
|
|
|
| 77 |
|
| 78 |
loop = asyncio.get_event_loop()
|
| 79 |
# upload the input/answer to google drive
|