Original topic:

Your try small python AI

(Topic created on: 07-17-2024 01:30 AM)
107 Views
dhushy101
Active Level 1
Options
Tech Expert
import requests
import pyfiglet
import itertools
import threading
import time
import sys

headers = {
 "content-type": "application/json",
 "X-RapidAPI-Key": "YOUR_API_KEY",
 "X-RapidAPI-Host": "simple-chatgpt-api.p.rapidapi.com"
}

def animate():
 for c in itertools.cycle(['|', '/', '-', '\\']):
 if done:
 break
 sys.stdout.write('\r' + c)
 sys.stdout.flush()
 time.sleep(0.1)
 # Clear the console output
 sys.stdout.write('\r')
 sys.stdout.flush()

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

if __name__ == "__main__":
 print(pyfiglet.figlet_format("AI Chat BOT"))
 print("Enter the question to ask:")
 print()
 while True:
 question = str(input(">> "))
 if question.lower() == 'q':
 print(">> Bye! Thanks for Using...")
 break
 # Loading animation
 done = False
 t = threading.Thread(target=animate)
 t.start()
 answer = ask(question)
 time.sleep(5)
 done = True
 t.join()
 print(">>", answer)
 print()

1 Comment
RISKYTAP722
Active Level 10
Tech Expert
Stay still Taking down notes 📝
0 Likes