Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,10 +4,21 @@ import os
|
|
| 4 |
|
| 5 |
HF_TOKEN = os.getenv("HF_TOKEN")
|
| 6 |
|
|
|
|
|
|
|
|
|
|
| 7 |
def respond(message, history: list[dict[str, str]]):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
client = InferenceClient(token=HF_TOKEN, model="openai/gpt-oss-20b")
|
| 9 |
|
| 10 |
-
messages = [
|
|
|
|
|
|
|
| 11 |
messages.extend(history)
|
| 12 |
messages.append({"role": "user", "content": message})
|
| 13 |
|
|
@@ -38,8 +49,8 @@ custom_css = """
|
|
| 38 |
background: white !important;
|
| 39 |
padding: 12px !important;
|
| 40 |
box-shadow: 0px 6px 25px rgba(0,0,0,0.12) !important;
|
| 41 |
-
max-width: 700px !important;
|
| 42 |
-
margin: 0 auto !important;
|
| 43 |
}
|
| 44 |
|
| 45 |
/* User bubble */
|
|
@@ -92,7 +103,7 @@ button:hover {
|
|
| 92 |
to {opacity: 1; transform: translateY(0);}
|
| 93 |
}
|
| 94 |
|
| 95 |
-
/* 🔒 Hide Gradio Footer
|
| 96 |
footer, .svelte-1yycg3h, .builder-bar, .wrap.svelte-1ipelgc {
|
| 97 |
display: none !important;
|
| 98 |
visibility: hidden !important;
|
|
|
|
| 4 |
|
| 5 |
HF_TOKEN = os.getenv("HF_TOKEN")
|
| 6 |
|
| 7 |
+
# ✅ Allowed subjects
|
| 8 |
+
ALLOWED_TOPICS = ["biology", "physics", "chemistry", "math", "mathematics"]
|
| 9 |
+
|
| 10 |
def respond(message, history: list[dict[str, str]]):
|
| 11 |
+
# 1️⃣ Check if the message contains allowed subjects
|
| 12 |
+
if not any(topic in message.lower() for topic in ALLOWED_TOPICS):
|
| 13 |
+
yield "❌ Sorry, I only know about Biology, Physics, Chemistry, and Maths. Please ask me about them."
|
| 14 |
+
return
|
| 15 |
+
|
| 16 |
+
# 2️⃣ Allowed topic → send to HuggingFace GPT
|
| 17 |
client = InferenceClient(token=HF_TOKEN, model="openai/gpt-oss-20b")
|
| 18 |
|
| 19 |
+
messages = [
|
| 20 |
+
{"role": "system", "content": "You are a friendly chatbot. You only answer questions about Biology, Physics, Chemistry, and Maths. For anything else, politely reply that you can't answer it."}
|
| 21 |
+
]
|
| 22 |
messages.extend(history)
|
| 23 |
messages.append({"role": "user", "content": message})
|
| 24 |
|
|
|
|
| 49 |
background: white !important;
|
| 50 |
padding: 12px !important;
|
| 51 |
box-shadow: 0px 6px 25px rgba(0,0,0,0.12) !important;
|
| 52 |
+
max-width: 700px !important;
|
| 53 |
+
margin: 0 auto !important;
|
| 54 |
}
|
| 55 |
|
| 56 |
/* User bubble */
|
|
|
|
| 103 |
to {opacity: 1; transform: translateY(0);}
|
| 104 |
}
|
| 105 |
|
| 106 |
+
/* 🔒 Hide Gradio Footer */
|
| 107 |
footer, .svelte-1yycg3h, .builder-bar, .wrap.svelte-1ipelgc {
|
| 108 |
display: none !important;
|
| 109 |
visibility: hidden !important;
|