ord / app.py
unijoh's picture
Create app.py
38116a9 verified
raw
history blame
1.64 kB
import gradio as gr
import pandas as pd
from datasets import load_dataset
# Load and parse the CSV file from Hugging Face
def load_data():
dataset = load_dataset("your-username/your-dataset-name", split="train")
df = pd.DataFrame(dataset)
lemmas = {}
current_lemma = None
for _, row in df.iterrows():
if row['#ORTO'] == '---':
current_lemma = None
elif current_lemma is None:
current_lemma = row['#ORTO'].replace("ORTO:", "")
lemmas[current_lemma] = []
else:
lemma_data = {
'PPOS': row['#PPOS'].replace("PPOS:", "") if pd.notna(row['#PPOS']) else "",
'PHON1': row['#PHON1'].replace("PHON:", "") if pd.notna(row['#PHON1']) else "",
'PHON2': row['#PHON2'].replace("PHON:", "") if pd.notna(row['#PHON2']) else "",
'COMM': row['#COMM'] if pd.notna(row['#COMM']) else ""
}
lemmas[current_lemma].append(lemma_data)
return lemmas
lemmas = load_data()
def search_lemma(lemma):
results = lemmas.get(lemma, None)
if not results:
return f"No results found for {lemma}"
response = f"Results for {lemma}:\n\n"
response += "PPOS\tPHON1\tPHON2\tCOMM\n"
for result in results:
response += f"{result['PPOS']}\t{result['PHON1']}\t{result['PHON2']}\t{result['COMM']}\n"
return response
iface = gr.Interface(
fn=search_lemma,
inputs="text",
outputs="text",
title="Lemma Search",
description="Enter a lemma to search for its declensions and pronunciations."
)
if __name__ == "__main__":
iface.launch()