Spaces:
Sleeping
Sleeping
Vikram Thangaraj
commited on
Commit
·
9efaf2a
1
Parent(s):
0fc0d0b
Initial commit Thirukural
Browse files- app.py +56 -0
- requirements.txt +2 -0
app.py
ADDED
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from datasets import load_dataset
|
3 |
+
|
4 |
+
# Load the Thirukural dataset
|
5 |
+
dataset = load_dataset("kodebot/Thirukural_tamil_with_meaning", split="train")
|
6 |
+
|
7 |
+
# Define chatbot logic
|
8 |
+
def search_thirukural(query):
|
9 |
+
results = []
|
10 |
+
query = query.lower()
|
11 |
+
|
12 |
+
for item in dataset:
|
13 |
+
if (
|
14 |
+
query in item["Couplet"].lower()
|
15 |
+
or query in item["Tamil_explanation"].lower()
|
16 |
+
or query in item["Couplet_English"].lower()
|
17 |
+
or query in item["English_explanation"].lower()
|
18 |
+
or query in item["Adhigaram_english"].lower()
|
19 |
+
or query == str(item["Number"])
|
20 |
+
):
|
21 |
+
results.append(item)
|
22 |
+
if len(results) >= 1:
|
23 |
+
break
|
24 |
+
|
25 |
+
if not results:
|
26 |
+
return "\ud83d\ude4f மன்னிக்கவும், பொருத்தமான குறள் எதுவும் இல்லை."
|
27 |
+
|
28 |
+
kural = results[0]
|
29 |
+
return f"""
|
30 |
+
📜 **குறள் #{kural['Number']}**
|
31 |
+
|
32 |
+
🔸 **தமிழில் குறள்**:
|
33 |
+
{kural['Couplet']}
|
34 |
+
|
35 |
+
📝 **விளக்கம்**:
|
36 |
+
{kural['Tamil_explanation']}
|
37 |
+
|
38 |
+
🔸 **Kural in English**:
|
39 |
+
{kural['Couplet_English']}
|
40 |
+
|
41 |
+
📝 **Explanation**:
|
42 |
+
{kural['English_explanation']}
|
43 |
+
"""
|
44 |
+
|
45 |
+
# Gradio interface
|
46 |
+
chat_interface = gr.Interface(
|
47 |
+
fn=search_thirukural,
|
48 |
+
inputs=gr.Textbox(lines=2, placeholder="உங்கள் கேள்வி / குறள் எண் / Adhigaram...", label="🔍 உங்கள் உள்ளீடு"),
|
49 |
+
outputs=gr.Textbox(label="📖 திருக்குறள் விளக்கம்"),
|
50 |
+
title="திருக்குறள் Chatbot 📜",
|
51 |
+
description="திருக்குறளின் மூலம் தமிழ் மரபை அறிந்து கொள்ளுங்கள்! ஒரு வார்த்தை, எண்ணிக்கை அல்லது தலைப்பை உள்ளிடுங்கள்.",
|
52 |
+
allow_flagging="never"
|
53 |
+
)
|
54 |
+
|
55 |
+
if __name__ == "__main__":
|
56 |
+
chat_interface.launch()
|
requirements.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
gradio
|
2 |
+
datasets
|