PST / app.py
Hacker0809's picture
Upload 2 files
b1ac2bc verified
import json
import difflib
import gradio as gr
# Load Q&A data
with open("premanand_qa_full.json", "r", encoding="utf-8") as f:
qa_pairs = json.load(f)
def get_answer(user_question):
questions = [item["question"] for item in qa_pairs]
closest_match = difflib.get_close_matches(user_question, questions, n=1, cutoff=0.4)
if closest_match:
for item in qa_pairs:
if item["question"] == closest_match[0]:
return f"🌸 {item['answer']}"
else:
return "🙏 बेटा, इस प्रश्न का उत्तर अभी मेरे पास नहीं है। कृपया कुछ और पूछो।"
# Gradio UI
iface = gr.Interface(
fn=get_answer,
inputs=gr.Textbox(lines=2, placeholder="प्रश्न पूछिए..."),
outputs="text",
title="🌼 श्री प्रेमानंद जी महाराज",
description="प्रेमानंद जी महाराज के भावों में आध्यात्मिक उत्तर प्राप्त करें।"
)
iface.launch()