Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
@@ -23,6 +23,12 @@ from langchain.chains.conversation.memory import ConversationBufferWindowMemory
|
|
23 |
from langchain.agents import Tool, initialize_agent
|
24 |
from huggingface_hub import login
|
25 |
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
# Check if the token is already set in the environment variables
|
27 |
hf_token = os.getenv("HF_TOKEN")
|
28 |
|
@@ -830,6 +836,26 @@ def update_images():
|
|
830 |
image_3 = generate_image(hardcoded_prompt_3)
|
831 |
return image_1, image_2, image_3
|
832 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
833 |
with gr.Blocks(theme='Pijush2023/scikit-learn-pijush') as demo:
|
834 |
|
835 |
with gr.Row():
|
@@ -870,7 +896,12 @@ with gr.Blocks(theme='Pijush2023/scikit-learn-pijush') as demo:
|
|
870 |
|
871 |
refresh_button = gr.Button("Refresh Images")
|
872 |
refresh_button.click(fn=update_images, inputs=None, outputs=[image_output_1, image_output_2, image_output_3])
|
873 |
-
|
|
|
|
|
|
|
|
|
|
|
874 |
demo.queue()
|
875 |
demo.launch(share=True)
|
876 |
|
|
|
23 |
from langchain.agents import Tool, initialize_agent
|
24 |
from huggingface_hub import login
|
25 |
|
26 |
+
|
27 |
+
import requests
|
28 |
+
from requests_oauthlib import OAuth2Session
|
29 |
+
from oauthlib.oauth2 import BackendApplicationClient
|
30 |
+
import os
|
31 |
+
|
32 |
# Check if the token is already set in the environment variables
|
33 |
hf_token = os.getenv("HF_TOKEN")
|
34 |
|
|
|
836 |
image_3 = generate_image(hardcoded_prompt_3)
|
837 |
return image_1, image_2, image_3
|
838 |
|
839 |
+
|
840 |
+
# OAuth 2.0 endpoints for Google
|
841 |
+
authorization_base_url = 'https://accounts.google.com/o/oauth2/auth'
|
842 |
+
token_url = 'https://accounts.google.com/o/oauth2/token'
|
843 |
+
scope = ['https://www.googleapis.com/auth/userinfo.profile', 'https://www.googleapis.com/auth/userinfo.email']
|
844 |
+
|
845 |
+
# Function to initiate the OAuth flow
|
846 |
+
def login():
|
847 |
+
google = OAuth2Session(GOOGLE_CLIENT_ID, scope=scope, redirect_uri=REDIRECT_URI)
|
848 |
+
authorization_url, state = google.authorization_url(authorization_base_url, access_type="offline", prompt="select_account")
|
849 |
+
return f'<a href="{authorization_url}" target="_self">Login with Google</a>'
|
850 |
+
|
851 |
+
# Function to handle the callback
|
852 |
+
def oauth_callback(url):
|
853 |
+
google = OAuth2Session(GOOGLE_CLIENT_ID, redirect_uri=REDIRECT_URI, scope=scope)
|
854 |
+
google.fetch_token(token_url, client_secret=GOOGLE_CLIENT_SECRET, authorization_response=url)
|
855 |
+
userinfo = google.get('https://www.googleapis.com/oauth2/v1/userinfo').json()
|
856 |
+
return f"Logged in as: {userinfo['name']} ({userinfo['email']})"
|
857 |
+
|
858 |
+
|
859 |
with gr.Blocks(theme='Pijush2023/scikit-learn-pijush') as demo:
|
860 |
|
861 |
with gr.Row():
|
|
|
896 |
|
897 |
refresh_button = gr.Button("Refresh Images")
|
898 |
refresh_button.click(fn=update_images, inputs=None, outputs=[image_output_1, image_output_2, image_output_3])
|
899 |
+
with gr.Column():
|
900 |
+
login_button = gr.HTML(login)
|
901 |
+
oauth_callback_url = gr.Textbox(label="Callback URL")
|
902 |
+
user_info = gr.HTML()
|
903 |
+
|
904 |
+
oauth_callback_url.submit(oauth_callback, inputs=[oauth_callback_url], outputs=[user_info])
|
905 |
demo.queue()
|
906 |
demo.launch(share=True)
|
907 |
|