Amazing-Python-Scripts
57 строк · 1.3 Кб
1import requests2import pyfiglet3import itertools4import threading5import time6import sys7
8url = "https://simple-chatgpt-api.p.rapidapi.com/ask"9
10
11headers = {12"content-type": "application/json",13"X-RapidAPI-Key": "OUR API KEY",14"X-RapidAPI-Host": "simple-chatgpt-api.p.rapidapi.com"15}
16
17
18def animate():19for c in itertools.cycle(['|', '/', '-', '\\']):20if done:21break22sys.stdout.write('\r' + c)23sys.stdout.flush()24time.sleep(0.1)25
26# Clear the console output27sys.stdout.write('\r')28sys.stdout.flush()29
30
31def ask(question):32payload = {"question": question}33response = requests.post(url, json=payload, headers=headers)34return response.json().get("answer")35
36
37if __name__ == "__main__":38print(pyfiglet.figlet_format("AI Chat BOT"))39print("Enter the question to ask:")40print()41while True:42# print("/>> ", end="")43question = str(input(">> "))44if (question == 'q'):45print(">> Bye! Thanks for Using...")46break47# loading48done = False49# here is the animation50t = threading.Thread(target=animate)51t.start()52answer = ask(question)53time.sleep(5)54done = True55t.join()56print(">> ", answer)57print()58