zinoubm commited on
Commit
b0abe84
·
1 Parent(s): 027a338

app is in beta and ready for testing

Browse files
Files changed (3) hide show
  1. app.py +13 -32
  2. gpt_summary.py +1 -1
  3. main.py +9 -1
app.py CHANGED
@@ -1,13 +1,10 @@
1
- from fastapi import FastAPI, Request, Depends
2
  from fastapi.responses import RedirectResponse
3
  from fastapi.responses import HTMLResponse
4
  from fastapi.staticfiles import StaticFiles
5
  from google_manager.constants import SCOPES
6
- from google_manager.auth import get_oauth_url
7
  from pages.auth_page import html_content
8
  import google_auth_oauthlib.flow
9
-
10
- # from fastapi_sessions import SessionMiddleware, get_session
11
  from starlette.middleware.sessions import SessionMiddleware
12
 
13
  import gradio as gr
@@ -20,46 +17,36 @@ app.mount("/assets", StaticFiles(directory="assets"), name="assets")
20
 
21
 
22
  @app.get("/", response_class=HTMLResponse)
23
- async def home():
24
- return HTMLResponse(content=html_content, status_code=200)
 
 
 
 
 
 
 
 
25
 
26
 
27
  @app.get("/auth")
28
  async def integreate_google(request: Request):
29
- # url = get_oauth_url(SCOPES, "http://127.0.0.1:8000/auth_callback")
30
  flow = google_auth_oauthlib.flow.Flow.from_client_secrets_file(
31
  "credentials.json", scopes=SCOPES
32
  )
33
 
34
- # flow.redirect_uri = "http://127.0.0.1:8000/gradio/?__theme=dark"
35
- # flow.redirect_uri = app.url_path_for(redirect_url)
36
  flow.redirect_uri = "http://127.0.0.1:8000/auth_callback"
37
 
38
- # Generate URL for request to Google's OAuth 2.0 server.
39
- # Use kwargs to set optional request parameters.
40
  authorization_url, state = flow.authorization_url(
41
- # Enable offline access so that you can refresh an access token without
42
- # re-prompting the user for permission. Recommended for web server apps.
43
  access_type="offline",
44
- # Enable incremental authorization. Recommended as a best practice.
45
  include_granted_scopes="true",
46
  )
47
  request.session["state"] = state
48
- print("authorization_url")
49
- print(authorization_url)
50
  return RedirectResponse(url=authorization_url)
51
 
52
 
53
  @app.get("/auth_callback")
54
  async def auth_callback(request: Request):
55
- # url = get_oauth_url(SCOPES)
56
- print("request")
57
- # print(request["code"])
58
- # return {"callback": "here"}
59
-
60
- # Specify the state when creating the flow in the callback so that it can
61
- # verified in the authorization server response.
62
- # if False:
63
  state = request.session["state"]
64
 
65
  flow = google_auth_oauthlib.flow.Flow.from_client_secrets_file(
@@ -71,15 +58,9 @@ async def auth_callback(request: Request):
71
  authorization_response = str(request.url)
72
 
73
  flow.fetch_token(authorization_response=authorization_response)
74
- if False:
75
- # flow.fetch_token(authorization_response=authorization_response)
76
-
77
- # Store credentials in the session.
78
- # ACTION ITEM: In a production app, you likely want to save these
79
- # credentials in a persistent database instead.
80
- credentials = flow.credentials
81
- request.session["credentials"] = credentials_to_dict(credentials)
82
 
 
 
83
  return RedirectResponse("/gradio")
84
 
85
 
 
1
+ from fastapi import FastAPI, Request
2
  from fastapi.responses import RedirectResponse
3
  from fastapi.responses import HTMLResponse
4
  from fastapi.staticfiles import StaticFiles
5
  from google_manager.constants import SCOPES
 
6
  from pages.auth_page import html_content
7
  import google_auth_oauthlib.flow
 
 
8
  from starlette.middleware.sessions import SessionMiddleware
9
 
10
  import gradio as gr
 
17
 
18
 
19
  @app.get("/", response_class=HTMLResponse)
20
+ async def home(request: Request):
21
+ print("request session")
22
+ print(request.session)
23
+ state = request.session.get("state", None)
24
+ print("state")
25
+ print(state)
26
+ if state:
27
+ return RedirectResponse("/gradio")
28
+ else:
29
+ return HTMLResponse(content=html_content, status_code=200)
30
 
31
 
32
  @app.get("/auth")
33
  async def integreate_google(request: Request):
 
34
  flow = google_auth_oauthlib.flow.Flow.from_client_secrets_file(
35
  "credentials.json", scopes=SCOPES
36
  )
37
 
 
 
38
  flow.redirect_uri = "http://127.0.0.1:8000/auth_callback"
39
 
 
 
40
  authorization_url, state = flow.authorization_url(
 
 
41
  access_type="offline",
 
42
  include_granted_scopes="true",
43
  )
44
  request.session["state"] = state
 
 
45
  return RedirectResponse(url=authorization_url)
46
 
47
 
48
  @app.get("/auth_callback")
49
  async def auth_callback(request: Request):
 
 
 
 
 
 
 
 
50
  state = request.session["state"]
51
 
52
  flow = google_auth_oauthlib.flow.Flow.from_client_secrets_file(
 
58
  authorization_response = str(request.url)
59
 
60
  flow.fetch_token(authorization_response=authorization_response)
 
 
 
 
 
 
 
 
61
 
62
+ credentials = flow.credentials
63
+ request.session["credentials"] = credentials_to_dict(credentials)
64
  return RedirectResponse("/gradio")
65
 
66
 
gpt_summary.py CHANGED
@@ -64,7 +64,7 @@ user:
64
  summary:
65
  {answer}
66
  """
67
- Fassade.upload_to_drive(doc_content)
68
 
69
  history.append((transcription, answer))
70
  response = history
 
64
  summary:
65
  {answer}
66
  """
67
+ # Fassade.upload_to_drive(doc_content)
68
 
69
  history.append((transcription, answer))
70
  response = history
main.py CHANGED
@@ -1,6 +1,14 @@
1
  import uvicorn
2
  from pathlib import Path
 
 
 
 
3
 
4
 
5
  if __name__ == "__main__":
6
- uvicorn.run(f"app:app", port=8000, reload=True)
 
 
 
 
 
1
  import uvicorn
2
  from pathlib import Path
3
+ import os
4
+
5
+ os.environ["OAUTHLIB_INSECURE_TRANSPORT"] = "1"
6
+ os.environ["OAUTHLIB_RELAX_TOKEN_SCOPE"] = "1"
7
 
8
 
9
  if __name__ == "__main__":
10
+ uvicorn.run(
11
+ f"app:app",
12
+ port=8000,
13
+ reload=True,
14
+ )