Spaces:
Sleeping
Sleeping
Upload folder using huggingface_hub
Browse files- .gitignore +3 -0
- api.py +47 -0
- app.py +83 -0
- assets/be'w.jpeg +0 -0
- assets/b/303/246gw.jpeg +0 -0
- assets/b/304/223ew.jpeg +0 -0
- assets/b/304/225w.jpeg +0 -0
- assets/g/303/241.jpeg +0 -0
- assets/g/303/242.jpeg +0 -0
- assets/g/303/242a.jpeg +0 -0
- assets/g/304/201.jpeg +0 -0
- assets/la.jpeg +0 -0
- assets/ll/303/272xh.jpeg +0 -0
- assets/luxh.jpeg +0 -0
- assets/l/305/253dx.jpeg +0 -0
- assets/nall/303/241.jpeg +0 -0
- assets/nall/303/242a.jpeg +0 -0
- assets/nal/304/201.jpeg +0 -0
- assets/ribiby.jpeg +0 -0
- assets/ribiib.jpeg +0 -0
- assets/rib/304/253iby.jpeg +0 -0
- assets/rig/303/246.jpeg +0 -0
- assets/rig/303/246/303/246.jpeg +0 -0
- assets/rig/307/243.jpeg +0 -0
- assets/r/303/246by.jpeg +0 -0
- assets/r/303/246/303/246by.jpeg +0 -0
- assets/r/307/243by.jpeg +0 -0
- keyfiledict.py +35 -0
- readme.md +7 -0
- requirements.txt +5 -0
.gitignore
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
.DS_Store
|
2 |
+
.env
|
3 |
+
.github
|
api.py
ADDED
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import sys
|
2 |
+
import subprocess
|
3 |
+
import os
|
4 |
+
import keyfiledict
|
5 |
+
import gspread
|
6 |
+
from oauth2client.service_account import ServiceAccountCredentials
|
7 |
+
from google.oauth2 import service_account
|
8 |
+
|
9 |
+
from dotenv import load_dotenv
|
10 |
+
|
11 |
+
load_dotenv()
|
12 |
+
|
13 |
+
# Upgrade pip
|
14 |
+
subprocess.check_call([sys.executable, "-m", "pip", "install", "--upgrade", "pip"])
|
15 |
+
|
16 |
+
# Check if the venv module is available
|
17 |
+
if sys.version_info >= (3, 3):
|
18 |
+
subprocess.run([sys.executable, "-m", "venv", "venv"])
|
19 |
+
else:
|
20 |
+
subprocess.run(["python", "-m", "venv", "venv"])
|
21 |
+
|
22 |
+
|
23 |
+
# Activate the virtual environment
|
24 |
+
activate_script = os.path.join("venv", "Scripts", "activate")
|
25 |
+
subprocess.run(activate_script, shell=True)
|
26 |
+
|
27 |
+
subprocess.check_call(["pip", "install", "google-api-python-client"])
|
28 |
+
|
29 |
+
# Install oauth2client
|
30 |
+
subprocess.check_call(["pip", "install", "oauth2client"])
|
31 |
+
subprocess.check_call(["pip", "install", "gspread"])
|
32 |
+
|
33 |
+
|
34 |
+
# credentials file downloaded from Google Developers Console
|
35 |
+
|
36 |
+
client = gspread.authorize(keyfiledict.credentials())
|
37 |
+
sheet = client.open('Zapotec Minimal Pairs').sheet1
|
38 |
+
|
39 |
+
# Get all values from the sheet
|
40 |
+
list_of_data = sheet.get_all_records()
|
41 |
+
|
42 |
+
# Get a range of cells
|
43 |
+
cells = sheet.range('C2:C32')
|
44 |
+
for cell in cells:
|
45 |
+
print(cell.value)
|
46 |
+
|
47 |
+
#print(list_of_data)
|
app.py
ADDED
@@ -0,0 +1,83 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gspread
|
2 |
+
import random
|
3 |
+
import os
|
4 |
+
import unicodedata
|
5 |
+
import gradio as gr
|
6 |
+
import keyfiledict
|
7 |
+
from oauth2client.service_account import ServiceAccountCredentials
|
8 |
+
from dotenv import load_dotenv
|
9 |
+
|
10 |
+
load_dotenv()
|
11 |
+
|
12 |
+
import json
|
13 |
+
|
14 |
+
|
15 |
+
def getData():
|
16 |
+
gc = gspread.service_account_from_dict(keyfiledict.create_keyfile_dict())
|
17 |
+
spreadsheet = gc.open_by_key(os.environ['OPEN_BY_KEY'])
|
18 |
+
|
19 |
+
data = spreadsheet.worksheet('main').get_all_values()
|
20 |
+
data = [[unicodedata.normalize('NFKC', row[0]).strip()] + row[1:] for row in data][1:] # normalize chars and remove header row
|
21 |
+
return data
|
22 |
+
|
23 |
+
##### game #####
|
24 |
+
|
25 |
+
## globals
|
26 |
+
data = getData()
|
27 |
+
possibleAnswers = [unicodedata.normalize('NFKC', filename.rsplit('.', 1)[0]).strip() for filename in os.listdir('./assets')]
|
28 |
+
answer = ""
|
29 |
+
minPairGroup = []
|
30 |
+
score = 0
|
31 |
+
|
32 |
+
## setters
|
33 |
+
def setRandAnswer():
|
34 |
+
global answer
|
35 |
+
global possibleAnswers
|
36 |
+
answer = random.choice(possibleAnswers)
|
37 |
+
|
38 |
+
def setMinPairGroup():
|
39 |
+
global answer
|
40 |
+
global minPairGroup
|
41 |
+
global data
|
42 |
+
answerRowIndex = next((i for i, sublist in enumerate(data) if sublist and sublist[0] == answer), -1)
|
43 |
+
minPairGroup = [sublist[0] for sublist in data if sublist[1] == data[answerRowIndex][1]]
|
44 |
+
|
45 |
+
def updateScore(radio):
|
46 |
+
global score
|
47 |
+
if radio == answer:
|
48 |
+
score += 5
|
49 |
+
else:
|
50 |
+
score -= 1
|
51 |
+
|
52 |
+
|
53 |
+
## gradio
|
54 |
+
# submit button function. updates everything.
|
55 |
+
def onSubmit(image, radio, scorebox):
|
56 |
+
global answer
|
57 |
+
global minPairGroup
|
58 |
+
global score
|
59 |
+
|
60 |
+
updateScore(radio)
|
61 |
+
setRandAnswer()
|
62 |
+
setMinPairGroup()
|
63 |
+
|
64 |
+
image = gr.Image(f'./assets/{answer}.jpeg', label=answer, show_label= False)
|
65 |
+
radio = gr.Radio(choices=minPairGroup, label='Which word is pictured?', value=None)
|
66 |
+
scorebox = gr.Markdown(f"# Score: {score}")
|
67 |
+
|
68 |
+
return image, radio, scorebox
|
69 |
+
|
70 |
+
# the interface
|
71 |
+
with gr.Blocks() as demo:
|
72 |
+
setRandAnswer()
|
73 |
+
setMinPairGroup()
|
74 |
+
|
75 |
+
with gr.Column():
|
76 |
+
scorebox = gr.Markdown(f"# Score: {score}")
|
77 |
+
image = gr.Image(f'./assets/{answer}.jpeg', label=answer, show_label= False)
|
78 |
+
radio = gr.Radio(choices=minPairGroup, label='Which word is pictured?')
|
79 |
+
submitButton = gr.Button("Submit")
|
80 |
+
submitButton.click(onSubmit, inputs= [image, radio, scorebox], outputs=[image, radio, scorebox])
|
81 |
+
|
82 |
+
|
83 |
+
demo.launch()
|
assets/be'w.jpeg
ADDED
assets/b/303/246gw.jpeg
ADDED
assets/b/304/223ew.jpeg
ADDED
assets/b/304/225w.jpeg
ADDED
assets/g/303/241.jpeg
ADDED
assets/g/303/242.jpeg
ADDED
assets/g/303/242a.jpeg
ADDED
assets/g/304/201.jpeg
ADDED
assets/la.jpeg
ADDED
assets/ll/303/272xh.jpeg
ADDED
assets/luxh.jpeg
ADDED
assets/l/305/253dx.jpeg
ADDED
assets/nall/303/241.jpeg
ADDED
assets/nall/303/242a.jpeg
ADDED
assets/nal/304/201.jpeg
ADDED
assets/ribiby.jpeg
ADDED
assets/ribiib.jpeg
ADDED
assets/rib/304/253iby.jpeg
ADDED
assets/rig/303/246.jpeg
ADDED
assets/rig/303/246/303/246.jpeg
ADDED
assets/rig/307/243.jpeg
ADDED
assets/r/303/246by.jpeg
ADDED
assets/r/303/246/303/246by.jpeg
ADDED
assets/r/307/243by.jpeg
ADDED
keyfiledict.py
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import gspread
|
3 |
+
import base64
|
4 |
+
from dotenv import load_dotenv
|
5 |
+
from oauth2client.service_account import ServiceAccountCredentials
|
6 |
+
from google.oauth2 import service_account
|
7 |
+
|
8 |
+
load_dotenv()
|
9 |
+
|
10 |
+
#Source: https://stackoverflow.com/questions/71544103/how-can-we-store-a-json-credential-to-env-variable-in-python
|
11 |
+
def create_keyfile_dict():
|
12 |
+
variables_keys = {
|
13 |
+
"type": os.getenv("TYPE"),
|
14 |
+
"project_id": os.getenv("PROJECT_ID"),
|
15 |
+
"private_key_id": os.getenv("PRIVATE_KEY_ID"),
|
16 |
+
"private_key": (os.environ['PRIVATE_KEY']).replace('\\n', '\n'),
|
17 |
+
"client_email": os.getenv("CLIENT_EMAIL"),
|
18 |
+
"client_id": os.getenv("CLIENT_ID"),
|
19 |
+
"auth_uri": os.getenv("AUTH_URI"),
|
20 |
+
"token_uri": os.getenv("TOKEN_URI"),
|
21 |
+
"auth_provider_x509_cert_url": os.getenv("AUTH_PROVIDER_X509_CERT_URL"),
|
22 |
+
"client_x509_cert_url": os.getenv("CLIENT_X509_CERT_URL")
|
23 |
+
}
|
24 |
+
return variables_keys
|
25 |
+
|
26 |
+
#Test
|
27 |
+
def define_scope():
|
28 |
+
scope = ['https://spreadsheets.google.com/feeds',
|
29 |
+
'https://www.googleapis.com/auth/drive']
|
30 |
+
return scope
|
31 |
+
|
32 |
+
def credentials():
|
33 |
+
creds = ServiceAccountCredentials.from_json_keyfile_name(create_keyfile_dict())
|
34 |
+
return creds
|
35 |
+
|
readme.md
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
title: Zapotec-Language-Game
|
3 |
+
app_file: app.py
|
4 |
+
sdk: gradio
|
5 |
+
sdk_version: 4.31.3
|
6 |
+
---
|
7 |
+
Zapotec Language Game
|
requirements.txt
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
gspread
|
2 |
+
gradio
|
3 |
+
oauth2client
|
4 |
+
python-dotenv
|
5 |
+
cryptography==2.2
|