|
import os |
|
import time |
|
import pandas as pd |
|
import gradio as gr |
|
|
|
|
|
def download_sheet_df(doc_id, sheet_id=0, header=0): |
|
sheet_url = f'https://docs.google.com/spreadsheets/d/{doc_id}/export?format=csv&gid={sheet_id}' |
|
return pd.read_csv(sheet_url, header=header) |
|
|
|
df = download_sheet_df(os.environ["SHEET_ID_SECRET"]) |
|
|
|
def find_reviews(uid): |
|
review_list = [] |
|
rows = [] |
|
try: |
|
for reviewer_n in [1, 2, 3, 4]: |
|
df_u = df[df[f"Reviewer_{reviewer_n}_UID_NUMBER_myucla"].astype(int) == int(uid)].copy() |
|
if len(df_u) == 1 and str(df_u.iloc[0]["Question 1 Response Edited"]) != "nan": |
|
rows.append(df_u.iloc[0]["Unnamed: 0"]) |
|
review_list.append(df_u.iloc[0][["Full_Name_myucla", "Question 1 Response Edited"]]) |
|
except ValueError: |
|
pass |
|
except Exception as e: |
|
raise e |
|
if len(review_list) == 0: |
|
review_list = pd.DataFrame([{"Error": "UID Not Found"}]) |
|
print(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()), f"Not Found uid: [{uid}]") |
|
else: |
|
print(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()), "Found rows:", sorted(rows)) |
|
return review_list[:3] |
|
|
|
demo = gr.Interface( |
|
fn=find_reviews, |
|
inputs="text", |
|
outputs=gr.Dataframe(headers=["Name", "Presentation Path"]), |
|
) |
|
demo.launch(debug=False) |