import gradio as gr from difflib import get_close_matches # FAQ Data faq_data = { "questions": [ { "question": "What is Resilient Coders?", "answer": "Resilient Coders is a nonprofit that trains young people of color for careers in tech." }, { "question": "Is the bootcamp free?", "answer": "Yes, it is completely free and participants get a stipend." }, { "question": "How long is the program?", "answer": "It typically lasts about 14–20 weeks." } ] } # Extract all questions for fuzzy matching questions_list = [q["question"] for q in faq_data["questions"]] # Chatbot function def chatbot(user_input): if not user_input.strip(): return "Please ask a question." match = get_close_matches(user_input, questions_list, n=1, cutoff=0.4) if match: for item in faq_data["questions"]: if item["question"] == match[0]: return item["answer"] return "Sorry, I only answer questions about Resilient Coders." # Gradio Interface demo = gr.Interface( fn=chatbot, inputs=gr.Textbox(lines=2, placeholder="Ask about Resilient Coders..."), outputs="text", title="Resilient Coders Chatbot", description="Ask me anything about Resilient Coders!" ) demo.launch()