Spaces:
Runtime error
Runtime error
Upload folder using huggingface_hub
Browse files- .github/workflows/update_space.yml +28 -0
- README.md +3 -9
- client_secret.json +10 -0
- main.py +24 -0
- service_account.json +13 -0
- test.py +63 -0
.github/workflows/update_space.yml
ADDED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
name: Run Python script
|
2 |
+
|
3 |
+
on:
|
4 |
+
push:
|
5 |
+
branches:
|
6 |
+
- main
|
7 |
+
|
8 |
+
jobs:
|
9 |
+
build:
|
10 |
+
runs-on: ubuntu-latest
|
11 |
+
|
12 |
+
steps:
|
13 |
+
- name: Checkout
|
14 |
+
uses: actions/checkout@v2
|
15 |
+
|
16 |
+
- name: Set up Python
|
17 |
+
uses: actions/setup-python@v2
|
18 |
+
with:
|
19 |
+
python-version: '3.9'
|
20 |
+
|
21 |
+
- name: Install Gradio
|
22 |
+
run: python -m pip install gradio
|
23 |
+
|
24 |
+
- name: Log in to Hugging Face
|
25 |
+
run: python -c 'import huggingface_hub; huggingface_hub.login(token="${{ secrets.hf_token }}")'
|
26 |
+
|
27 |
+
- name: Deploy to Spaces
|
28 |
+
run: gradio deploy
|
README.md
CHANGED
@@ -1,12 +1,6 @@
|
|
1 |
---
|
2 |
-
title:
|
3 |
-
|
4 |
-
colorFrom: gray
|
5 |
-
colorTo: green
|
6 |
sdk: gradio
|
7 |
-
sdk_version: 3.
|
8 |
-
app_file: app.py
|
9 |
-
pinned: false
|
10 |
---
|
11 |
-
|
12 |
-
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
1 |
---
|
2 |
+
title: admin-gradio
|
3 |
+
app_file: main.py
|
|
|
|
|
4 |
sdk: gradio
|
5 |
+
sdk_version: 3.40.1
|
|
|
|
|
6 |
---
|
|
|
|
client_secret.json
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"web": {
|
3 |
+
"client_id": "884906000817-ufeecv03nd14i8eiim8rc48tth7ihri3.apps.googleusercontent.com",
|
4 |
+
"project_id": "food-business-401610",
|
5 |
+
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
|
6 |
+
"token_uri": "https://oauth2.googleapis.com/token",
|
7 |
+
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
|
8 |
+
"client_secret": "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"
|
9 |
+
}
|
10 |
+
}
|
main.py
ADDED
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import gspread
|
3 |
+
from oauth2client.service_account import ServiceAccountCredentials
|
4 |
+
|
5 |
+
# Use creds to create a client to interact with the Google Drive API
|
6 |
+
scope = ["https://spreadsheets.google.com/feeds",'https://www.googleapis.com/auth/spreadsheets',"https://www.googleapis.com/auth/drive.file","https://www.googleapis.com/auth/drive"]
|
7 |
+
creds = ServiceAccountCredentials.from_json_keyfile_name('service_account.json', scope)
|
8 |
+
client = gspread.authorize(creds)
|
9 |
+
|
10 |
+
# Find a workbook by name and open the specific sheet
|
11 |
+
spreadsheet = client.open("Food or Drink Order")
|
12 |
+
sheet = spreadsheet.worksheet('Gradio')
|
13 |
+
|
14 |
+
def write_to_sheet(name, email):
|
15 |
+
row = [name, email]
|
16 |
+
sheet.append_row(row)
|
17 |
+
return f"Data {name} and {email} has been written to the sheet."
|
18 |
+
|
19 |
+
iface = gr.Interface(fn=write_to_sheet,
|
20 |
+
inputs=["text", "text"],
|
21 |
+
outputs="text",
|
22 |
+
interpretation="default")
|
23 |
+
|
24 |
+
iface.launch(share=True)
|
service_account.json
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"type": "service_account",
|
3 |
+
"project_id": "smartdigital-374003",
|
4 |
+
"private_key_id": "08f9e4eb3d7a369983c40dcbe0826b1c73426850",
|
5 |
+
"private_key": "-----BEGIN PRIVATE KEY-----\nMIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDOnMDYkvNu6Oow\nzeUQvY6lUBn9rx6OSf4YL3vSyCbz1O+SXPNZPtmiZSj7bAbRe5aAORQnJy9IhJh6\njuqT10bpQYkuYWATAh5sKPD4gD2CC1ouEgySp7nLqxIyAazqHhznqBmsYB42wC1P\nSQ7EpTMZq0SvwBLP2XU+lX6opgPpzb/uIFQmnUIRG1PMKVKFcgRY+UgiBIn6hQYi\ns7s+N+QaKyB5Zedm72n9+0b/bYaS+5GVviX6xzohnCzKBr+ABVrOL8aycxkbRF0R\nrJoW0mJzCnrPBXVApmtcjzt15aqW5ps5dneEtw/IYeaUGa4UJix8sNpQepmbTecv\n/rPgko5JAgMBAAECggEAJxBeKdSG8DZbaQTUxXiBiuH9OAivJ0n4H8yChdTQAJQH\nA85NOFd4wIqN2BORqnPKfc3M8KYo+3YOekWhNniicKGydTF1/8ILzHllLibY+kh5\nMXK6K9RIfaiHlSrZ7Z3p6ybOS9gUfleReYcforB1W+oU34HaTLAZyc5sFyjkXoTw\nAD+HMN6Q4/gJA7bVRslvjWHknka1c+LpF6vW6s7McpsXM0XAkQvWZkG7EchnNQRg\nQDEw0gtIiSPrfTyQuGYT9G20YYWUPe5e9xz9+nNflozLtTLkxK1vjQfpPsjspGSe\nMknHnFBTzA73TuqPmQ1O1oVHLsKB8WVZGW5rRGT23QKBgQD5QeoKBWRrO6bJdlUa\nconCyUZc3dIFw4OT20bcmqwFVS1wnHIZS4ZOnFERmPE1sfUUQI8IFpK0t8sjA2lq\nFXnVQiosrIiBSY8a+B2YCrSeTZHfLXv0SXg0PPlyhJqcgmEkm9CwMwi8jS36pWVK\niwfdSvbVr5mrKL4H7yAJ9xVw2wKBgQDUM4ZxIMB6Y6PU8bvR0F3on4PwE6Oi7JnW\nDjf8+ans6dEgg/MLQ+qy6/tgJ//hSOnJfrj2CHt0xe5Hq6Gcd5s8myw9df+hRV8g\nzmsj294XPjwWyUul35pjHq/qESsVvQ/AEIoIuikgdhbTFKj5SdaZqDCH5vwlof3g\njz5jcbJEqwKBgQCodro9h6N1Ll3tr8KZG2ysb+jUfz+hkaDuX7enBgrZl9YcVEBx\nhDAEFXZdVGdCiUJBK9j/+HGzHr12rqmif11Wm19xzjJ8X0EPUz59Mk8c5wR+OHmc\ng8NwWv2lPqZYvW32ljEXxYZUGX9H9l1dYlYwZKgriIFtwx2csyuOUKb3HQKBgQC+\nL9gFOKeKihdiWa5OpIQmZCGqYM++zHQsh93iXBnSftWyYNDKffqylhJc4jzSO7ld\noLhBuuR7ipK/pbJZPFHkBeemxkVw024pRxh7sSnihyLwAUZNypTi1bQxA2YsO6EM\nMUal/8OwlmZqlQ/FLkqquTWV+I5xZDjYtUnjcxmltQKBgAR+L4ucBwM8OpcjN9Op\nnH8HLqpYE29Gvy4GevF0eH8yH8ojc+9YUbADgXJ4/jEckpufYumssaVDA0t2WP0S\nMCDT1arrLvf/pZfyOYN2nPOOnRzLP0SyJ15BM47/vyGrIL5CV3PCnzWJ7KQJtQnu\nvQqPVu9j+3tlXIiT2ouBQx9j\n-----END PRIVATE KEY-----\n",
|
6 |
+
"client_email": "food-service@smartdigital-374003.iam.gserviceaccount.com",
|
7 |
+
"client_id": "104800359076849857441",
|
8 |
+
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
|
9 |
+
"token_uri": "https://oauth2.googleapis.com/token",
|
10 |
+
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
|
11 |
+
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/food-service%40smartdigital-374003.iam.gserviceaccount.com",
|
12 |
+
"universe_domain": "googleapis.com"
|
13 |
+
}
|
test.py
ADDED
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from __future__ import print_function
|
2 |
+
|
3 |
+
import os.path
|
4 |
+
|
5 |
+
from google.auth.transport.requests import Request
|
6 |
+
from google.oauth2.credentials import Credentials
|
7 |
+
from google_auth_oauthlib.flow import InstalledAppFlow
|
8 |
+
from googleapiclient.discovery import build
|
9 |
+
from googleapiclient.errors import HttpError
|
10 |
+
|
11 |
+
# If modifying these scopes, delete the file token.json.
|
12 |
+
SCOPES = ['https://www.googleapis.com/auth/spreadsheets.readonly']
|
13 |
+
|
14 |
+
# The ID and range of a sample spreadsheet.
|
15 |
+
SAMPLE_SPREADSHEET_ID = '1BxiMVs0XRA5nFMdKvBdBZjgmUUqptlbs74OgvE2upms'
|
16 |
+
SAMPLE_RANGE_NAME = 'Class Data!A2:E'
|
17 |
+
|
18 |
+
|
19 |
+
def main():
|
20 |
+
"""Shows basic usage of the Sheets API.
|
21 |
+
Prints values from a sample spreadsheet.
|
22 |
+
"""
|
23 |
+
creds = None
|
24 |
+
# The file token.json stores the user's access and refresh tokens, and is
|
25 |
+
# created automatically when the authorization flow completes for the first
|
26 |
+
# time.
|
27 |
+
if os.path.exists('service_account.json'):
|
28 |
+
creds = Credentials.from_authorized_user_file('service_account.json', SCOPES)
|
29 |
+
# If there are no (valid) credentials available, let the user log in.
|
30 |
+
if not creds or not creds.valid:
|
31 |
+
if creds and creds.expired and creds.refresh_token:
|
32 |
+
creds.refresh(Request())
|
33 |
+
else:
|
34 |
+
flow = InstalledAppFlow.from_client_secrets_file(
|
35 |
+
'client_secret.json', SCOPES)
|
36 |
+
creds = flow.run_local_server(port=0)
|
37 |
+
# Save the credentials for the next run
|
38 |
+
with open('service_account.json', 'w') as token:
|
39 |
+
token.write(creds.to_json())
|
40 |
+
|
41 |
+
try:
|
42 |
+
service = build('sheets', 'v4', credentials=creds)
|
43 |
+
|
44 |
+
# Call the Sheets API
|
45 |
+
sheet = service.spreadsheets()
|
46 |
+
result = sheet.values().get(spreadsheetId=SAMPLE_SPREADSHEET_ID,
|
47 |
+
range=SAMPLE_RANGE_NAME).execute()
|
48 |
+
values = result.get('values', [])
|
49 |
+
|
50 |
+
if not values:
|
51 |
+
print('No data found.')
|
52 |
+
return
|
53 |
+
|
54 |
+
print('Name, Major:')
|
55 |
+
for row in values:
|
56 |
+
# Print columns A and E, which correspond to indices 0 and 4.
|
57 |
+
print('%s, %s' % (row[0], row[4]))
|
58 |
+
except HttpError as err:
|
59 |
+
print(err)
|
60 |
+
|
61 |
+
|
62 |
+
if __name__ == '__main__':
|
63 |
+
main()
|