Spaces:
Runtime error
Runtime error
| import gradio as gr | |
| import os | |
| from huggingface_hub import InferenceClient | |
| # Safely get HF API Token | |
| HF_TOKEN = os.environ.get("HF_API_TOKEN") | |
| if not HF_TOKEN: | |
| raise ValueError("Missing Hugging Face API token. Please set 'HF_API_TOKEN' in your environment.") | |
| # Connect to Hugging Face model | |
| client = InferenceClient( | |
| model="HuggingFaceH4/zephyr-7b-beta", | |
| token=HF_TOKEN | |
| ) | |
| # Q&A pairs about Resilient Coders | |
| rc_qa_examples = [ | |
| ("What is Resilient Coders?", "Resilient Coders is a free, stipended, full-time coding bootcamp that trains people of color for careers in tech. The program is fully remote and includes a $500 bi-weekly stipend."), | |
| ("Is the bootcamp really free?", "Yes! The program is completely free. Participants are also paid a bi-weekly stipend. There is no repayment required."), | |
| ("How long is the program?", "The bootcamp typically runs for 18 to 20 weeks."), | |
| ("Do I need to know how to code before applying?", "No prior experience is required. We teach you from scratch."), | |
| ("Is your program online or in-person?", "The program is 100% remote."), | |
| ("What technical skills are taught?", "We teach HTML, CSS, JavaScript, React, Node.js, MongoDB, Git, and more."), | |
| ("What soft skills are included?", "We focus heavily on communication, public speaking, teamwork, and job readiness."), | |
| ("Who is eligible to apply?", "Applicants should be 18–35 years old, low-income, and located in Greater Boston, Philadelphia, Maine, or nearby states. Must be eligible to work in the U.S. and not hold advanced post-secondary degrees."), | |
| ("What is the stipend amount?", "Accepted students receive $500 every two weeks during the program."), | |
| ("When does the next cohort start?", "The next cohort runs from August 11, 2025, to December 12, 2025."), | |
| ("When is the application deadline?", "Applications for Fall 2025 are not open yet. Submit an interest form to get notified."), | |
| ("How do I apply?", "Step 1: Watch our free intro class. Step 2: Submit your application. Step 3: Attend a hackathon if invited. Step 4: Interview. Step 5: Onboard."), | |
| ("What happens after I apply?", "You'll receive a confirmation email. If eligible, you’ll be invited to a virtual hackathon. If you don’t hear back within 7–10 business days, email recruiting@resilientcoders.org."), | |
| ("Do I have to attend a hackathon?", "Yes. Attending a virtual hackathon is required to move forward in the application process."), | |
| ("Can I work while enrolled?", "The bootcamp is intensive and full-time. Most participants cannot hold a job during the program."), | |
| ("What do you look for in candidates?", "We value curiosity, persistence, and collaboration."), | |
| ("Can older applicants still apply?", "We prioritize applicants aged 18–35, but encourage anyone outside the range to apply. All applications are reviewed case by case."), | |
| ("Do you help graduates find jobs?", "Yes, but placement is not guaranteed. We support grads with hiring events, job search coaching, and networking."), | |
| ("What kinds of jobs do alumni get?", "Roles like Software Engineer, Junior Developer, QA Engineer, Technical Support Specialist, and more."), | |
| ("Where do graduates work?", "Our alumni have been hired at companies like Amazon Audible, Wayfair, Athenahealth, Cargurus, Liberty Mutual, and more."), | |
| ("What’s the average graduate salary?", "Average salaries range between $81K and $98K, depending on the cohort and location."), | |
| ("What if I fall behind or don’t meet expectations?", "We call that a 'redirect.' You may be unenrolled from the program and no longer receive the stipend."), | |
| ("Is there a waitlist or alternative if I don’t get in?", "Yes. If you’re not selected, we encourage you to reapply for the next cohort or explore alternatives like FreeCodeCamp, #100Devs, or Apprenti."), | |
| ("Are there other programs for people under 18?", "Yes! Check out FutureBOS, The Possible Zone, and other youth-centered programs in your area."), | |
| ("Can employers partner with Resilient Coders?", "Yes! We’re always seeking hiring partners, sponsors, and volunteer mentors. Contact partnerships@resilientcoders.org."), | |
| ("Do you accept volunteers?", "Absolutely. We’re looking for mentors, technical interviewers, mock interviewers, and career coaches."), | |
| ("How can I support the program?", "You can volunteer your time, donate, host a hiring event, or spread the word. Learn more at resilientcoders.org."), | |
| ("What tools do students use during the program?", "Students work with VS Code, GitHub, Slack, Zoom, Glitch, Remo, and other industry-standard tools."), | |
| ("Is there a demo day?", "Yes! Each cohort ends with a public demo day where students present their final projects to employers and the community."), | |
| ("What are Community Hours?", "They are live sessions where students can get support, ask questions, and connect with mentors. Held on Tuesdays and Thursdays from 3:30–6:00 PM EST."), | |
| ("Resilient Coders Staff Team", "Ayanna Lott‑Pollard — Executive Director. Leon Noel — Managing Director of Engineering. Stephanie Castaños — Managing Director of Strategic Partnerships. Atiya Byrom — Development Associate. Mayra Vega — Recruitment Manager & Community Advocate. Alex Soto — Expert in Residence. Erica Mendez — Expert in Residence"), | |
| ("What support do students get?", "Daily instruction, mentorship, career coaching, project feedback, and community support."), | |
| ] | |
| # Response generator | |
| def respond(message, history, system_message, max_tokens, temperature, top_p): | |
| messages = [{"role": "system", "content": system_message.strip()}] | |
| # Add example Q&A pairs to ground the model | |
| for q, a in rc_qa_examples: | |
| messages.extend([ | |
| {"role": "user", "content": q}, | |
| {"role": "assistant", "content": a} | |
| ]) | |
| # Add chat history | |
| for user_msg, bot_reply in history: | |
| if user_msg: | |
| messages.append({"role": "user", "content": user_msg}) | |
| if bot_reply: | |
| messages.append({"role": "assistant", "content": bot_reply}) | |
| # Add current message | |
| messages.append({"role": "user", "content": message}) | |
| # Streaming response from Hugging Face | |
| response = "" | |
| for chunk in client.chat_completion( | |
| messages=messages, | |
| max_tokens=max_tokens, | |
| temperature=temperature, | |
| top_p=top_p, | |
| stream=True | |
| ): | |
| delta = chunk.choices[0].delta.content | |
| if delta: | |
| response += delta | |
| yield response | |
| # Optional: Custom CSS | |
| custom_css = """ | |
| body, .gradio-container { | |
| background-color: #fff0f0; | |
| } | |
| h1, h2 { | |
| font-family: Switzer, sans-serif; | |
| color:#ed1b24; | |
| } | |
| container{ | |
| border:solid 1px #ed1b24; | |
| } | |
| p{color: black;} | |
| """ | |
| # Build the Gradio UI | |
| demo = gr.ChatInterface( | |
| fn=respond, | |
| additional_inputs=[ | |
| gr.Textbox(value="You are a helpful assistant trained *only* on verified content from https://www.resilientcoders.org. If a user asks anything not covered by the provided examples, respond with: 'I'm still learning. Please contact hello@resilientcoders.org for more info.' Never speculate or use outside data.", label="System message"), | |
| gr.Slider(minimum=64, maximum=2048, value=512, step=1, label="Max tokens"), | |
| gr.Slider(minimum=0.1, maximum=2.0, value=0.7, step=0.1, label="Temperature"), | |
| gr.Slider(minimum=0.1, maximum=1.0, value=0.95, step=0.05, label="Top-p"), | |
| ], | |
| title="Resilient Coders FAQ Chatbot", | |
| description="Ask anything about Resilient Coders bootcamp!", | |
| css=custom_css | |
| ) | |
| if __name__ == "__main__": | |
| demo.launch() | |