amaltese commited on
Commit
46b622e
·
verified ·
1 Parent(s): b97b30a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -3
app.py CHANGED
@@ -4,8 +4,14 @@ import requests
4
  from transformers import pipeline
5
  import wikipediaapi
6
 
7
- # Load historical figures and tutor topics from Wikipedia dynamically
8
- wiki_wiki = wikipediaapi.Wikipedia("en")
 
 
 
 
 
 
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.")