Download app.py from DGRDN/SCIIBOTT: direct link, hf CLI and curl.
- Browser
- Download file 1.17 kB
-
https://huggingface.co/spaces/DGRDN/SCIIBOTT/resolve/main/app.py
- Command line
-
hf download hf://spaces/DGRDN/SCIIBOTT/app.py
-
curl -L -o app.py https://huggingface.co/spaces/DGRDN/SCIIBOTT/resolve/main/app.py
1.17 kB
| import gradio as gr | |
| import wikipedia | |
| wikipedia.set_lang("en") | |
| def science_bot(user_input): | |
| topic = user_input.lower().strip() | |
| for prefix in ["what is", "define", "explain", "tell me about"]: | |
| if topic.startswith(prefix): | |
| topic = topic.replace(prefix, "").strip() | |
| try: | |
| return wikipedia.summary(topic, sentences=3) | |
| except wikipedia.exceptions.DisambiguationError as e: | |
| return f"⚠️ That topic is ambiguous. Try one of these:\n{', '.join(e.options[:5])}" | |
| except wikipedia.exceptions.PageError: | |
| try: | |
| return wikipedia.summary(topic.title(), sentences=3) | |
| except: | |
| try: | |
| return wikipedia.summary(f"{topic} (physics)", sentences=3) | |
| except: | |
| return f"❌ I couldn't find anything on '{topic}'. Try a different science topic." | |
| demo = gr.Interface( | |
| fn=science_bot, | |
| inputs=gr.Textbox(lines=1, placeholder="Ask a science question..."), | |
| outputs=gr.Textbox(lines=8, label="🧠 Science Answer"), | |
| title="🔬 SciWhiz: Science Chatbot", | |
| description="Ask me science questions. I’ll answer using Wikipedia!" | |
| ) | |
| demo.launch() |