| import gradio as gr |
| import wikipedia |
| import requests |
| from bs4 import BeautifulSoup |
| import pyjokes |
|
|
|
|
| def code(name): |
| name = name.split('learn')[-1] |
| name = name.split('start')[-1] |
| name = name.split()[0] |
| s={} |
| result = {"",""} |
| text = "" |
| url = "https://www.w3schools.com/"+name+"/"+name+"_syntax.asp" |
| r = requests.get(url) |
| soup = BeautifulSoup(r.text,"html.parser") |
|
|
| |
| heading_object=soup.find_all('div') |
| n=1 |
| for info in heading_object: |
| info1 = str(info) |
| if '</script>' not in info1 and '<div class="w3-col l10 m12" id="main">' in info1: |
|
|
| |
| return str(info.text).split('Next ❯')[1] |
| n=n+1 |
|
|
|
|
|
|
| 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\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 |
| |
| import openai |
| openai.api_key = "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" |
| def aitext(word): |
| response = openai.Completion.create( |
| model="text-davinci-003", |
| prompt=word, |
| temperature=0.9, |
| max_tokens=200, |
| top_p=1, |
| frequency_penalty=0, |
| presence_penalty=0.6, |
| stop=[" Human:", " AI:"] |
| ) |
|
|
| return response.choices[0].text |
|
|
| def google(name): |
| result = {"",""} |
| text ="" |
| if "how to learn" in name or "steps for learning" in name or "step for learning" in name or "steps for" in name or "step for" in name: |
| try: |
| text = code(name)+"\n\n" |
| except: |
| 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') |
| |
| for info in heading_object: |
| |
| |
| if '<div class="BNeawe s3v9rd AP7Wnd"><div><div><div class="BNeawe s3v9rd AP7Wnd">' in str(info): |
| if '›' not in str(info.text) : |
| result.add(info.text) |
| n=0 |
| for i in result: |
| if n!=0: |
| i = i.split("·",1) |
| try: |
| i = i[1] |
| except: |
| i = i[0] |
| i=i.split("Duration") |
| |
| i = i[0] |
| text = text +str(n)+"\t"+i+"\n\n" |
| n=n+1 |
| return text |
|
|
| def greet(name1): |
| name = name1.lower() |
| |
| 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 "who developed you" in name or "what is you" in name or "who mad you" in name or "who made you" in name: |
| return "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() |
|
|
|
|
|
|