Upload folder using huggingface_hub
Browse files- .gitignore +3 -0
- __pycache__/keyfiledict.cpython-312.pyc +0 -0
- api.py +47 -0
- app.py +105 -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 +34 -0
- readme.md +7 -0
- requirements.txt +5 -0
.gitignore
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
.DS_Store
|
| 2 |
+
.env
|
| 3 |
+
.github
|
__pycache__/keyfiledict.cpython-312.pyc
ADDED
|
Binary file (1.88 kB). View file
|
|
|
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,105 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
## gradio
|
| 53 |
+
|
| 54 |
+
def nextQuestion(image, radio, scorebox):
|
| 55 |
+
global answer
|
| 56 |
+
global minPairGroup
|
| 57 |
+
global score
|
| 58 |
+
|
| 59 |
+
setRandAnswer()
|
| 60 |
+
setMinPairGroup()
|
| 61 |
+
|
| 62 |
+
image = gr.Image(f'./assets/{answer}.jpeg', label=answer, show_label= False)
|
| 63 |
+
radio = gr.Radio(choices=minPairGroup, label='Which word is pictured?')
|
| 64 |
+
scorebox = gr.Markdown(f"# Score: {score}")
|
| 65 |
+
output_column = gr.Column(visible=False)
|
| 66 |
+
input_column = gr.Column(visible=True)
|
| 67 |
+
|
| 68 |
+
|
| 69 |
+
return image, radio, scorebox, output_column, input_column
|
| 70 |
+
|
| 71 |
+
# submit button function. updates everything.
|
| 72 |
+
def onSubmit(radio, scorebox):
|
| 73 |
+
global answer
|
| 74 |
+
global score
|
| 75 |
+
|
| 76 |
+
updateScore(radio)
|
| 77 |
+
input_column = gr.Column(visible=False)
|
| 78 |
+
output_column = gr.Column(visible=True)
|
| 79 |
+
results = f"{answer} is correct. Good job!" if radio==answer else f"Incorrect. The correct answer was {answer}."
|
| 80 |
+
scorebox = gr.Markdown(f"# Score: {score}")
|
| 81 |
+
|
| 82 |
+
return scorebox, output_column, results, input_column
|
| 83 |
+
|
| 84 |
+
# the interface
|
| 85 |
+
with gr.Blocks() as demo:
|
| 86 |
+
setRandAnswer()
|
| 87 |
+
setMinPairGroup()
|
| 88 |
+
|
| 89 |
+
with gr.Column():
|
| 90 |
+
scorebox = gr.Markdown(f"# Score: {score}")
|
| 91 |
+
image = gr.Image(f'./assets/{answer}.jpeg', label=answer, show_label= False)
|
| 92 |
+
radio = gr.Radio(choices=minPairGroup, label='Which word is pictured?')
|
| 93 |
+
|
| 94 |
+
with gr.Column(visible=True) as input_column:
|
| 95 |
+
submitButton = gr.Button("Submit")
|
| 96 |
+
|
| 97 |
+
with gr.Column(visible=False) as output_column:
|
| 98 |
+
results = gr.Textbox(label="Correct Answer")
|
| 99 |
+
nextButton = gr.Button("Next")
|
| 100 |
+
nextButton.click(nextQuestion, inputs= [image, radio, scorebox], outputs=[image, radio, scorebox, output_column, input_column])
|
| 101 |
+
|
| 102 |
+
|
| 103 |
+
submitButton.click(onSubmit, inputs= [radio, scorebox], outputs=[scorebox, output_column, results, input_column])
|
| 104 |
+
|
| 105 |
+
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,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
def define_scope():
|
| 27 |
+
scope = ['https://spreadsheets.google.com/feeds',
|
| 28 |
+
'https://www.googleapis.com/auth/drive']
|
| 29 |
+
return scope
|
| 30 |
+
|
| 31 |
+
def credentials():
|
| 32 |
+
creds = ServiceAccountCredentials.from_json_keyfile_name(create_keyfile_dict())
|
| 33 |
+
return creds
|
| 34 |
+
|
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
|