unijoh commited on
Commit
38116a9
1 Parent(s): 970a82c

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +50 -0
app.py ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import pandas as pd
3
+ from datasets import load_dataset
4
+
5
+ # Load and parse the CSV file from Hugging Face
6
+ def load_data():
7
+ dataset = load_dataset("your-username/your-dataset-name", split="train")
8
+ df = pd.DataFrame(dataset)
9
+ lemmas = {}
10
+ current_lemma = None
11
+
12
+ for _, row in df.iterrows():
13
+ if row['#ORTO'] == '---':
14
+ current_lemma = None
15
+ elif current_lemma is None:
16
+ current_lemma = row['#ORTO'].replace("ORTO:", "")
17
+ lemmas[current_lemma] = []
18
+ else:
19
+ lemma_data = {
20
+ 'PPOS': row['#PPOS'].replace("PPOS:", "") if pd.notna(row['#PPOS']) else "",
21
+ 'PHON1': row['#PHON1'].replace("PHON:", "") if pd.notna(row['#PHON1']) else "",
22
+ 'PHON2': row['#PHON2'].replace("PHON:", "") if pd.notna(row['#PHON2']) else "",
23
+ 'COMM': row['#COMM'] if pd.notna(row['#COMM']) else ""
24
+ }
25
+ lemmas[current_lemma].append(lemma_data)
26
+
27
+ return lemmas
28
+
29
+ lemmas = load_data()
30
+
31
+ def search_lemma(lemma):
32
+ results = lemmas.get(lemma, None)
33
+ if not results:
34
+ return f"No results found for {lemma}"
35
+ response = f"Results for {lemma}:\n\n"
36
+ response += "PPOS\tPHON1\tPHON2\tCOMM\n"
37
+ for result in results:
38
+ response += f"{result['PPOS']}\t{result['PHON1']}\t{result['PHON2']}\t{result['COMM']}\n"
39
+ return response
40
+
41
+ iface = gr.Interface(
42
+ fn=search_lemma,
43
+ inputs="text",
44
+ outputs="text",
45
+ title="Lemma Search",
46
+ description="Enter a lemma to search for its declensions and pronunciations."
47
+ )
48
+
49
+ if __name__ == "__main__":
50
+ iface.launch()