Amazing-Python-Scripts

Форк
0
57 строк · 1.3 Кб
1
import requests
2
import pyfiglet
3
import itertools
4
import threading
5
import time
6
import sys
7

8
url = "https://simple-chatgpt-api.p.rapidapi.com/ask"
9

10

11
headers = {
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

18
def animate():
19
    for c in itertools.cycle(['|', '/', '-', '\\']):
20
        if done:
21
            break
22
        sys.stdout.write('\r' + c)
23
        sys.stdout.flush()
24
        time.sleep(0.1)
25

26
    # Clear the console output
27
    sys.stdout.write('\r')
28
    sys.stdout.flush()
29

30

31
def ask(question):
32
    payload = {"question": question}
33
    response = requests.post(url, json=payload, headers=headers)
34
    return response.json().get("answer")
35

36

37
if __name__ == "__main__":
38
    print(pyfiglet.figlet_format("AI Chat BOT"))
39
    print("Enter the question to ask:")
40
    print()
41
    while True:
42
        # print("/>>  ", end="")
43
        question = str(input(">>  "))
44
        if (question == 'q'):
45
            print(">>  Bye! Thanks for Using...")
46
            break
47
        # loading
48
        done = False
49
        # here is the animation
50
        t = threading.Thread(target=animate)
51
        t.start()
52
        answer = ask(question)
53
        time.sleep(5)
54
        done = True
55
        t.join()
56
        print(">> ", answer)
57
        print()
58

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.