Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -4,8 +4,14 @@ import requests
|
|
4 |
from transformers import pipeline
|
5 |
import wikipediaapi
|
6 |
|
7 |
-
#
|
8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
|
10 |
# Load local AI model (Mistral-7B or Llama-2)
|
11 |
chat_model = pipeline("text-generation", model="mistralai/Mistral-7B-Instruct-v0.1")
|
@@ -53,4 +59,4 @@ st.sidebar.subheader("Deployment Instructions")
|
|
53 |
st.sidebar.markdown("1. Ensure `transformers` and `wikipedia-api` libraries are installed.")
|
54 |
st.sidebar.markdown("2. Rename `chatbot.py` to `app.py` for Hugging Face Spaces.")
|
55 |
st.sidebar.markdown("3. Run `streamlit run app.py` locally.")
|
56 |
-
st.sidebar.markdown("4. Deploy on [Hugging Face Spaces](https://huggingface.co/spaces) or Replit.")
|
|
|
4 |
from transformers import pipeline
|
5 |
import wikipediaapi
|
6 |
|
7 |
+
# Custom User-Agent to avoid API blocking
|
8 |
+
USER_AGENT = "HistoricalChatbot/1.0 (Contact: [email protected])"
|
9 |
+
|
10 |
+
# Load Wikipedia API with custom headers
|
11 |
+
wiki_wiki = wikipediaapi.Wikipedia(
|
12 |
+
"en",
|
13 |
+
headers={"User-Agent": USER_AGENT}
|
14 |
+
)
|
15 |
|
16 |
# Load local AI model (Mistral-7B or Llama-2)
|
17 |
chat_model = pipeline("text-generation", model="mistralai/Mistral-7B-Instruct-v0.1")
|
|
|
59 |
st.sidebar.markdown("1. Ensure `transformers` and `wikipedia-api` libraries are installed.")
|
60 |
st.sidebar.markdown("2. Rename `chatbot.py` to `app.py` for Hugging Face Spaces.")
|
61 |
st.sidebar.markdown("3. Run `streamlit run app.py` locally.")
|
62 |
+
st.sidebar.markdown("4. Deploy on [Hugging Face Spaces](https://huggingface.co/spaces) or Replit.")
|