SmartHadith_ENG / app.py
Adr740's picture
Update app.py
312fd66
import gradio as gr
from get_hadiths import HadithSearch
import os
from functools import partial
hadith_search = HadithSearch(api_key=os.environ.get("apk"))
title = "Smart Hadith"
desc = "### This is a simple AI tool. Write your problem or situation (personal or not) and quickly find relevant hadiths on this topic or a problem you have. Just type in plain English how you feel. More on how does it work: https://adam-rida.medium.com/smart-hadith-ed7b6c9e0b2d\nContact suggestions/questions: [email protected]\n\n"
warning = """
Warning!\n **PLEASE READ THE DISCLAIMER BELOW** This isn't a 100% accurate tool;
not all Hadiths are present in the database, and some results might be repetitive. If that's the case, try generating more Hadiths with the selector.\n
More information describing how the tool works is coming soon\n\n
## DISCLAIMER\n\n
THIS TOOL IS INTENDED FOR REFERENCE PURPOSES ONLY AND IS NOT INTENDED TO BE TAKEN AS RELIGIOUS ADVICE. THE HADITHS DISPLAYED BY THIS TOOL ARE NOT INTENDED TO BE USED AS A SOLE SOURCE OF RELIGIOUS GUIDANCE.
USERS ARE RESPONSIBLE FOR CONDUCTING THEIR RESEARCH AND SEEKING GUIDANCE FROM RELIGIOUS SCHOLARS.\n\nPLEASE NOTE THAT THE CONTENT DISPLAYED BY THIS TOOL IS NOT GUARANTEED TO BE ACCURATE, COMPLETE, OR UP-TO-DATE.\n\n
THE DEVELOPERS OF THIS TOOL WILL NOT BE HELD RESPONSIBLE FOR ANY DECISIONS MADE BY THE USERS OF THIS TOOL THAT ARE BASED ON THE CONTENT DISPLAYED BY THIS TOOL.\n\nHadiths gathered from this repository:
https://www.kaggle.com/datasets/fahd09/hadith-dataset
"""
def update_results(text_area, number_to_display=10):
print("run update results")
results = hadith_search.search_hadiths(text_area, number_to_display)
return results
with gr.Blocks(title=title) as demo:
gr.Markdown(f"## {title}")
gr.Markdown(desc)
with gr.Accordion("READ BEFORE USING THE TOOL!", open=False):
gr.Markdown(warning)
with gr.Row():
with gr.Column(scale=4):
text_area = gr.Textbox(placeholder="I heard it was advised to drink water in three segments", lines=3, label="Describe your situation/problem with your own words (story, keywords, topics, examples etc...)")
with gr.Column(scale=1):
number_to_display = gr.Number(value=10,label = "Number of hadiths to display")
submit_button = gr.Button(value="Find hadiths relevant to my story")
pass
#fn = partial(update_results)
with gr.Accordion("Relevant Hadiths (Please run again if results are not satisfying)"):
response_display = gr.Markdown("Empty")
submit_button.click(fn=update_results, inputs=[text_area,number_to_display], outputs=[response_display])
demo.launch(max_threads=40, show_error=True)