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