import gradio as gr import wikipedia import requests from bs4 import BeautifulSoup import pyjokes def joke(): # importing installed library 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] #print(wikipedia.search(text, results=20)) #print(text) out = "try this key words :\n"+str(wikipedia.search(text, results=10))+"\n\n" for i in wikipedia.search(text, results=3): try: result = wikipedia.summary(i) if " " in result.lower(): #print(result) #print() out = out + result+"\n" except: continue return out def google(name): result = {"",""} text = "" 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 if '
' in str(info): if '›' not in str(info.text) : result.add(info.text) for i in result: text = text +i+"\n" return text def greet(name1): name = name1.lower() #n= if "who are you" in name or "what is you" in name or "your name" in name or"who r u" in name: return "Im Ai Based Chatbot Created by ssebowa.org" if "tell me a joke" in name or "the joke" in name: return joke() if "love you" in name or "i love" in name: return "me too" if "marry me" in name or "marry" in name: return "im not intrested" if "your age" in name or "what is your age" in name: return "Im not a human so i don't have age" if "thank u" in name or "thanks" in name or "thank you" in name: return "ok welcome ....!" return google(name) iface = gr.Interface(fn=greet, inputs="text", outputs="text") iface.launch()