Spaces:
Running
Running
import gradio as gr | |
import random | |
import pandas as pd | |
import requests | |
# URL of the file you want to download | |
url = "https://raw.githubusercontent.com/Bestroi150/NLP_LAT_COLL/main/corpus_sermo_vulgaris_token.csv" | |
# Specify the local file name to save the downloaded content | |
local_filename = "corpus_sermo_vulgaris_token.csv" | |
# Send an HTTP GET request to the URL | |
response = requests.get(url) | |
# Check if the request was successful (status code 200) | |
if response.status_code == 200: | |
# Open the local file for writing and save the content from the response | |
with open(local_filename, 'wb') as f: | |
f.write(response.content) | |
print(f"File '{local_filename}' has been downloaded and saved.") | |
else: | |
print(f"Failed to download the file. Status code: {response.status_code}") | |
data = pd.read_csv('corpus_sermo_vulgaris_token.csv') | |
analytics_data = pd.DataFrame(columns=["Entry", "Clicks"]) # Declare as a global variable | |
def get_random_entry(): | |
random_row = data.sample() | |
token = random_row['token'].values[0] | |
pos = random_row['pos'].values[0] | |
if pos == "n": | |
entry_str = f"<b>Token:</b> {token}, <b>POS:</b> Noun, <b>Lemma:</b> {random_row['lemma'].values[0]}, <b>Gender:</b> {random_row['gender'].values[0]}, <b>Case:</b> {random_row['case'].values[0]}, <b>Number:</b> {random_row['number'].values[0]}" | |
elif pos == "adp": | |
entry_str = f"<b>Token:</b> {token}, <b>POS:</b> Preposition, <b>Lemma:</b> {random_row['lemma'].values[0]}" | |
elif pos == "adi": | |
entry_str = f"<b>Token:</b> {token}, <b>POS:</b> Adjective, <b>Lemma:</b> {random_row['lemma'].values[0]}, <b>Gender:</b> {random_row['gender'].values[0]}, <b>Case:</b> {random_row['case'].values[0]}, <b>Number:</b> {random_row['number'].values[0]}" | |
elif pos == "adv": | |
entry_str = f"<b>Token:</b> {token}, <b>POS:</b> Adverb, <b>Lemma:</b> {random_row['lemma'].values[0]}" | |
elif pos == "pron": | |
entry_str = f"<b>Token:</b> {token}, <b>POS:</b> Pronoun, <b>Lemma:</b> {random_row['lemma'].values[0]}" | |
elif pos == "v": | |
entry_str = f"<b>Token:</b> {token}, <b>POS:</b> Verb, <b>Lemma:</b> {random_row['lemma'].values[0]}, <b>Aspect:</b> {random_row['aspect'].values[0]}, <b>Tense:</b> {random_row['tense'].values[0]}, <b>VerbForm:</b> {random_row['verbForm'].values[0]}, <b>Voice:</b> {random_row['voice'].values[0]}, <b>Mood:</b> {random_row['mood'].values[0]}" | |
else: | |
entry_str = f"<b>Token:</b> {token}, Lemma: {random_row['lemma'].values[0]}," | |
if pd.notna(random_row['aspect'].values[0]): | |
entry_str += f" Aspect: {random_row['aspect'].values[0]}," | |
if pd.notna(random_row['tense'].values[0]): | |
entry_str += f" Tense: {random_row['tense'].values[0]}," | |
if pd.notna(random_row['verbForm'].values[0]): | |
entry_str += f" VerbForm: {random_row['verbForm'].values[0]}," | |
if pd.notna(random_row['voice'].values[0]): | |
entry_str += f" Voice: {random_row['voice'].values[0]}," | |
if pd.notna(random_row['mood'].values[0]): | |
entry_str += f" Mood: {random_row['mood'].values[0]}," | |
if pd.notna(random_row['number'].values[0]): | |
entry_str += f" Number: {random_row['number'].values[0]}," | |
if pd.notna(random_row['person'].values[0]): | |
entry_str += f" Person: {random_row['person'].values[0]}," | |
if pd.notna(random_row['case'].values[0]): | |
entry_str += f" Case: {random_row['case'].values[0]}," | |
if pd.notna(random_row['gender'].values[0]): | |
entry_str += f" Gender: {random_row['gender'].values[0]}" | |
# Remove the trailing comma | |
entry_str = entry_str.rstrip(',') | |
return entry_str | |
# Remove the trailing comma | |
entry_str = entry_str.rstrip(',') | |
return entry_str | |
iface = gr.Interface( | |
fn=get_random_entry, | |
inputs=None, | |
outputs="html", # Use HTML as the output type | |
live=True, | |
theme=gr.themes.Base(primary_hue="teal").set( | |
button_primary_background_fill="*primary_400", | |
button_primary_background_fill_hover="*primary_300", | |
)) | |
iface.launch( | |
share=True | |
) | |