Abdul-Haseeb commited on
Commit
d85098b
·
verified ·
1 Parent(s): a5c129c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -2
app.py CHANGED
@@ -57,11 +57,14 @@ from urllib.parse import quote
57
 
58
  def fetch_wikipedia_link(topic: str) -> str | None:
59
  try:
60
- # URL encode the topic
61
  encoded_topic = quote(topic)
62
  api_url = f"https://en.wikipedia.org/api/rest_v1/page/summary/{encoded_topic}"
63
 
64
- response = requests.get(api_url, timeout=5)
 
 
 
 
65
 
66
  if response.status_code != 200:
67
  st.error(f"Failed to fetch Wikipedia content for '{topic}' (status {response.status_code})")
 
57
 
58
  def fetch_wikipedia_link(topic: str) -> str | None:
59
  try:
 
60
  encoded_topic = quote(topic)
61
  api_url = f"https://en.wikipedia.org/api/rest_v1/page/summary/{encoded_topic}"
62
 
63
+ headers = {
64
+ "User-Agent": "QuizBot/1.0 (https://huggingface.co/your-space) Python/3.x"
65
+ }
66
+
67
+ response = requests.get(api_url, headers=headers, timeout=5)
68
 
69
  if response.status_code != 200:
70
  st.error(f"Failed to fetch Wikipedia content for '{topic}' (status {response.status_code})")