DGRDN commited on
Commit
ba3f08a
·
verified ·
1 Parent(s): 0cdfd40

Create SCIBOT

Browse files
Files changed (1) hide show
  1. SCIBOT +29 -0
SCIBOT ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ !pip install wikipedia
2
+
3
+ import wikipedia
4
+ wikipedia.set_lang("en")
5
+
6
+ def science_bot(user_input):
7
+ topic = user_input.lower().strip()
8
+ for prefix in ["what is", "define", "explain", "tell me about"]:
9
+ if topic.startswith(prefix):
10
+ topic = topic.replace(prefix, "").strip()
11
+
12
+ try:
13
+ return wikipedia.summary(topic, sentences=3)
14
+ except wikipedia.exceptions.DisambiguationError as e:
15
+ return f"⚠️ That topic is ambiguous. Try one of these:\n{', '.join(e.options[:5])}"
16
+ except wikipedia.exceptions.PageError:
17
+ try:
18
+ return wikipedia.summary(topic.title(), sentences=3)
19
+ except:
20
+ try:
21
+ return wikipedia.summary(f"{topic} (physics)", sentences=3)
22
+ except:
23
+ return f"❌ I couldn't find anything on '{topic}'. Try a different science topic."
24
+
25
+ while True:
26
+ user_input = input("Ask a science question (or type 'exit'): ")
27
+ if user_input.lower() == "exit":
28
+ break
29
+ print(science_bot(user_input))