chat bot attempt sherika
Browse files
phase/Student_view/chatbot.py
CHANGED
|
@@ -6,10 +6,12 @@ from huggingface_hub import InferenceClient
|
|
| 6 |
|
| 7 |
# Read from Space Secrets (Settings → Variables & secrets)
|
| 8 |
HF_TOKEN = os.getenv("HF_TOKEN")
|
| 9 |
-
|
|
|
|
| 10 |
|
| 11 |
if not HF_TOKEN:
|
| 12 |
st.error("⚠️ HF_TOKEN is not set. In your Space, add a Secret named HF_TOKEN.")
|
|
|
|
| 13 |
client = InferenceClient(model=GEN_MODEL, token=HF_TOKEN)
|
| 14 |
|
| 15 |
def add_message(text: str, sender: str):
|
|
@@ -31,6 +33,7 @@ def _reply_with_hf():
|
|
| 31 |
convo.append(f"{role}: {m['text']}")
|
| 32 |
prompt = (system + "\n\n" + "\n".join(convo) + "\nASSISTANT:").strip()
|
| 33 |
|
|
|
|
| 34 |
return client.text_generation(
|
| 35 |
prompt,
|
| 36 |
max_new_tokens=220,
|
|
@@ -38,6 +41,7 @@ def _reply_with_hf():
|
|
| 38 |
stream=False
|
| 39 |
)
|
| 40 |
|
|
|
|
| 41 |
def show_page():
|
| 42 |
st.title("🤖 AI Financial Tutor")
|
| 43 |
st.caption("Get personalized help with your financial questions")
|
|
|
|
| 6 |
|
| 7 |
# Read from Space Secrets (Settings → Variables & secrets)
|
| 8 |
HF_TOKEN = os.getenv("HF_TOKEN")
|
| 9 |
+
# Replace with your chosen model
|
| 10 |
+
GEN_MODEL = "HuggingFaceTB/SmolLM2-135M-Instruct" # CPU-friendly
|
| 11 |
|
| 12 |
if not HF_TOKEN:
|
| 13 |
st.error("⚠️ HF_TOKEN is not set. In your Space, add a Secret named HF_TOKEN.")
|
| 14 |
+
|
| 15 |
client = InferenceClient(model=GEN_MODEL, token=HF_TOKEN)
|
| 16 |
|
| 17 |
def add_message(text: str, sender: str):
|
|
|
|
| 33 |
convo.append(f"{role}: {m['text']}")
|
| 34 |
prompt = (system + "\n\n" + "\n".join(convo) + "\nASSISTANT:").strip()
|
| 35 |
|
| 36 |
+
# Call the Hugging Face Inference API with a lightweight model
|
| 37 |
return client.text_generation(
|
| 38 |
prompt,
|
| 39 |
max_new_tokens=220,
|
|
|
|
| 41 |
stream=False
|
| 42 |
)
|
| 43 |
|
| 44 |
+
|
| 45 |
def show_page():
|
| 46 |
st.title("🤖 AI Financial Tutor")
|
| 47 |
st.caption("Get personalized help with your financial questions")
|