Spaces:
Sleeping
Sleeping
| import pandas as pd | |
| sheet_id = "1xDGQTL8QXFKK2t_FFZhswfuZc_BwznsWKHeOkFRRXYY" | |
| sheet_name = "Token-Level_Annotation" | |
| import pandas as pd | |
| def df_to_conllu(df): | |
| conllu_sentences = [] | |
| for sent_id, group in df.groupby("SENT_ID"): | |
| row0 = group.iloc[0] | |
| text = row0["TEXT"] | |
| text_en = row0["TEXT_EN"] | |
| genre = row0["GENRE"] | |
| source = row0["SOURCE"] | |
| annotator = row0["ANNOTATOR"] | |
| status = row0["STATUS"] | |
| lines = [ | |
| f"# sent_id = {sent_id}", | |
| f"# text = {text}", | |
| f"# text_en = {text_en}", | |
| f"# genre = {genre}", | |
| f"# source = {source}", | |
| f"# annotator = {annotator}", | |
| f"# status = {status}", | |
| ] | |
| for _, row in group.iterrows(): | |
| fields = [ | |
| str(row["ID"]), | |
| str(row["FORM"]), | |
| str(row["LEMMA"]), | |
| str(row["UPOS"]), | |
| str(row["XPOS"]), | |
| str(row["FEATS"]), | |
| str(row["HEAD"]), | |
| str(row["DEPREL"]), | |
| str(row["DEPS"]), | |
| str(row["MISC"]), | |
| ] | |
| lines.append("\t".join(fields)) | |
| conllu_sentences.append("\n".join(lines)) | |
| return "\n\n".join(conllu_sentences) + "\n" | |
| def convert(sheet_id, sheet_name): | |
| url = f"https://docs.google.com/spreadsheets/d/{sheet_id}/gviz/tq?tqx=out:csv&sheet={sheet_name}" | |
| df = pd.read_csv(url) | |
| cols = ", ".join(df.columns.tolist()) | |
| conllu = df_to_conllu(df) | |
| return f"Columns: {cols}\n\n{conllu}" | |
| # ------------------------- | |
| # RUN WITHOUT UI | |
| # ------------------------- | |
| sheet_id = "1xDGQTL8QXFKK2t_FFZhswfuZc_BwznsWKHeOkFRRXYY" | |
| sheet_name = "Token-Level_Annotation" | |
| result = convert(sheet_id, sheet_name) | |
| print(result) | |
| import gradio as gr | |
| def noop(): | |
| return "Running." | |
| demo = gr.Interface(fn=noop, inputs=None, outputs="text") | |
| demo.launch() | |