File size: 1,364 Bytes
d4f5b64
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30bda6c
 
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
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()