| import gradio as gr |
| import wikipedia |
| import requests |
| from bs4 import BeautifulSoup |
| import pyjokes |
|
|
|
|
|
|
| def joke(): |
| |
|
|
| My_joke = pyjokes.get_joke(language="en", category="neutral") |
|
|
| return My_joke |
|
|
|
|
| def wiki(name): |
| text = name |
| text = text.split("the")[-1] |
| text = text.split("is a")[-1] |
| text = text.split("by")[-1] |
| |
| |
| out = "try this key words :\n"+str(wikipedia.search(text, results=10))+"\n" |
| for i in wikipedia.search(text, results=3): |
| try: |
| result = wikipedia.summary(i) |
| if " " in result.lower(): |
| |
| |
| out = out + result+"\n" |
| except: |
| continue |
| return out |
|
|
| def greet(name): |
| if "who are you" in name or "who r u" in name: |
|
|
| return "im ssebowa.org created Chatbot" |
|
|
|
|
| if "tell me a joke" in name or "joke" in name: |
| return joke() |
|
|
| return wiki(name) |
| def google(): |
| url = "https://www.google.com/search?q="+name |
| r = requests.get(url) |
| |
| soup = BeautifulSoup(r.text,"html.parser") |
| |
| heading_object=soup.find_all('div') |
| n=1 |
| for info in heading_object: |
| |
| n=n+1 |
| p="" |
| if n==9: |
| |
| result = info.getText()[170:] |
| result = result.split(".") |
| for s in result[:10]: |
| p = p + "\n"+s |
| p = p.replace("org › wiki ›","") |
| p = p.replace("wikipedia","") |
| p = p.replace("com › dictionary ›","") |
| print(p) |
| return p |
| break |
|
|
|
|
| iface = gr.Interface(fn=greet, inputs="text", outputs="text") |
| iface.launch() |