Spaces:
Runtime error
Runtime error
| import gradio as gr | |
| from get_similar_hadiths import HadithSearch | |
| import os | |
| from functools import partial | |
| hadith_search = HadithSearch(api_key=os.environ.get("apk")) | |
| hadith_search.load_data_from_json("embeded_data.json") | |
| title = "Smart Hadith -> English version available here:https://huggingface.co/spaces/Adr740/SmartHadith_ENG" | |
| desc = "### Bienvenue dans Smart Hadith. Expliquer une situation ou un problème (personnel ou non) et Smart Hadith va retrouver des hadith qui peuvent potentiellement vous aider. Plus d'informations sur le fonctionnement: https://adam-rida.medium.com/smart-hadith-ed7b6c9e0b2d\n Contact suggestions/questions: [adamrida.ra@gmail.com](mailto:adamrida.ra@gmail.com)" | |
| warning = "\n\n**AVERTISSEMENT (seul 3000 hadiths environ sont présents)**\nCET OUTIL EST DESTINÉ À DES FINS DE RÉFÉRENCE AFIN DE FACILITER LA RECHERCHE SUR LES HADITHS (PAROLES ET ACTES PROPHÉTIQUES). IL N'EST PAS DESTINÉ À ÊTRE UTILISÉ EN TANT QU'OUTIL D'ORIENTATION OU POUR TOUT AUTRE BUT.\nPOUR TOUTE QUESTION RELIGIEUSE, LES UTILISATEURS SONT INVITÉS À CHERCHER CONSEIL AUPRÈS DE RÉFÉRENCE ADÉQUATE ET RECONNU. VEUILLEZ NOTER QUE LE CONTENU AFFICHÉ PAR CET OUTIL N'EST PAS GARANTI COMME ÉTANT PRÉCIS, COMPLET OU À JOUR. LES DÉVELOPPEURS DE CET OUTIL NE SERONT TENUS RESPONSABLES EN AUCUN CAS DE TOUT USAGE OU DÉCISION FAIT PAR LES UTILISATEURS." | |
| def update_results(text_area, number_to_display=10): | |
| user_input = text_area | |
| results = hadith_search.search_hadiths(user_input, number_to_display) | |
| return results | |
| with gr.Blocks(title=title) as demo: | |
| gr.Markdown(f"## {title}") | |
| gr.Markdown(desc) | |
| with gr.Accordion("A LIRE AVANT UTILISATION!", open=False): | |
| gr.Markdown(warning) | |
| with gr.Row(): | |
| with gr.Column(scale=4): | |
| text_area = gr.Textbox(placeholder="On m'a dit qu'il était conseillé de manger en étant assis", lines=3, label="Décrivez votre situation avec vos mots (histoire, mots clés, sujet etc...)") | |
| with gr.Column(scale=1): | |
| number_to_display = gr.Number(value=10,label = "Nombre de hadiths à afficher") | |
| submit_button = gr.Button(value="Trouver hadiths pertinent") | |
| pass | |
| fn = partial(update_results) | |
| with gr.Accordion("Hadiths Pertinents (Relancez si les résultats ne vous conviennent pas)"): | |
| response_display = gr.Markdown("Empty") | |
| submit_button.click(fn=fn, inputs=[text_area,number_to_display], outputs=[response_display]) | |
| demo.launch(max_threads=40) |