Spaces:
Sleeping
Sleeping
Commit
·
62b3eea
1
Parent(s):
19b4a5a
add query bq testing function
Browse files- app.py +31 -0
- requirements.txt +3 -0
- t.html +0 -0
app.py
CHANGED
|
@@ -1,8 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
from theme import Seafoam
|
| 4 |
|
| 5 |
seafoam = Seafoam()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
with open('achievement.html', 'r', encoding='utf-8') as file:
|
| 7 |
html = file.read()
|
| 8 |
|
|
@@ -116,11 +132,26 @@ with gr.Blocks(theme=seafoam, css=css) as demo:
|
|
| 116 |
i = gr.Textbox(value='0', elem_id="test1")
|
| 117 |
o = gr.Textbox()
|
| 118 |
b = gr.Button(elem_id="test2")
|
|
|
|
| 119 |
|
| 120 |
def print_text(t):
|
| 121 |
return t
|
| 122 |
|
| 123 |
b.click(print_text, i, o,)
|
| 124 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 125 |
if __name__ == "__main__":
|
| 126 |
demo.launch()
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import json
|
| 3 |
+
|
| 4 |
import gradio as gr
|
| 5 |
+
import numpy as np
|
| 6 |
+
from google.oauth2.service_account import Credentials
|
| 7 |
+
from google.cloud import bigquery
|
| 8 |
|
| 9 |
from theme import Seafoam
|
| 10 |
|
| 11 |
seafoam = Seafoam()
|
| 12 |
+
|
| 13 |
+
SCOPES = ["https://www.googleapis.com/auth/bigquery"]
|
| 14 |
+
SERVICE_ACCOUNT_INFO = os.getenv("GBQ_TOKEN")
|
| 15 |
+
service_account_info_dict = json.loads(SERVICE_ACCOUNT_INFO)
|
| 16 |
+
|
| 17 |
+
creds = Credentials.from_service_account_info(
|
| 18 |
+
service_account_info_dict, scopes=SCOPES
|
| 19 |
+
)
|
| 20 |
+
client = bigquery.Client(credentials=creds, project=service_account_info_dict['project_id'])
|
| 21 |
+
|
| 22 |
with open('achievement.html', 'r', encoding='utf-8') as file:
|
| 23 |
html = file.read()
|
| 24 |
|
|
|
|
| 132 |
i = gr.Textbox(value='0', elem_id="test1")
|
| 133 |
o = gr.Textbox()
|
| 134 |
b = gr.Button(elem_id="test2")
|
| 135 |
+
df = gr.DataFrame()
|
| 136 |
|
| 137 |
def print_text(t):
|
| 138 |
return t
|
| 139 |
|
| 140 |
b.click(print_text, i, o,)
|
| 141 |
|
| 142 |
+
def run_query(user_id):
|
| 143 |
+
QUERY = (
|
| 144 |
+
'SELECT created_at, points, user_role, joined, developer FROM `datastore_backup.UserData`',
|
| 145 |
+
f'WHERE user_id = {user_id}'
|
| 146 |
+
)
|
| 147 |
+
query_job = client.query(QUERY)
|
| 148 |
+
query_result = query_job.result()
|
| 149 |
+
df = query_result.to_dataframe()
|
| 150 |
+
# Select a subset of columns
|
| 151 |
+
df = df[["created_at", "points", "user_role", "joined", "developer"]]
|
| 152 |
+
# Convert numeric columns to standard numpy types
|
| 153 |
+
df = df.astype({"points": np.int64})
|
| 154 |
+
return df
|
| 155 |
+
|
| 156 |
if __name__ == "__main__":
|
| 157 |
demo.launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
google-cloud-bigquery[pandas]
|
| 2 |
+
numpy
|
| 3 |
+
pandas
|
t.html
DELETED
|
File without changes
|