#๐ Xeno Prompt Enhancer
16 messages ยท Page 1 of 1 (latest)
@shadow musk
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
import requests
import json
import time
from colorama import Fore, Style, init
import sys
import threading
init(autoreset=True)
def spinner(text):
stop_spinner = False
def spinning():
while not stop_spinner:
for cursor in '|/-\\':
sys.stdout.write(Fore.YELLOW + f'\r{text} {cursor}')
sys.stdout.flush()
time.sleep(0.1)
sys.stdout.write('\r')
thread = threading.Thread(target=spinning)
thread.start()
return lambda: setattr(sys.modules[__name__], 'stop_spinner', True)
def check_api_status():
url = "hidden"
payload = {"message": "test"}
headers = {
hidden
}
response = requests.post(url, data=json.dumps(payload), headers=headers)
def enhance_prompt(user_input):
url = "hidden"
payload = {"message": user_input}
headers = {
hidden
}
try:
response = requests.post(url, data=json.dumps(payload), headers=headers)
if response.status_code == 200:
return response.text
else:
return f"Error: Received status code {response.status_code}"
except Exception as e:
return f"An error occurred: {str(e)}"
def main():
print(Fore.CYAN + Style.BRIGHT + "\n=========== WELCOME TO XENO ===========")
print(Fore.YELLOW + "\nThe ultimate tool for enhancing your prompts!\n")
print(Fore.GREEN + "[STATUS] API is UP and Running!")
print(Fore.MAGENTA + "Type 'exit' to quit the program.")
while True:
user_input = input(Fore.CYAN + Style.BRIGHT + "\nEnter your prompt: " + Style.RESET_ALL).strip()
if user_input.lower() == 'exit':
print(Fore.YELLOW + "\nThank you for using Xeno. Goodbye!")
break
if not user_input:
print(Fore.RED + "Prompt cannot be empty. Please try again.")
continue
stop_spin = spinner("Enhancing your prompt...")
result = enhance_prompt(user_input)
stop_spin()
print(f"\n{Fore.GREEN if 'Error' not in result else Fore.RED}{result}")
if __name__ == "__main__":
main()
the code is above and my issue is supposed to be easy
My issue is that after it provides the new enhanced prompt it displays enhancing prompt under again
even tho I added stop_spin()
Probably because in spinner(), the stop_spinner variable is a local, and thus when you call stop_spin() (which sets a module attribute i.e. a global) it has no effect. The original spinner's still running.
Oh
so the solution is that I should make the local variable global?
That would work. But a better solution is to keep it local and make the stop_spin lambda a proper function which starts:
nonlocal stop_spinner
stop_spinner = True
That way stop_spinner is the local used for this spinner. And that means you could it future run multiple spinners. Also, it avoids cluttering the global space with variables.
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.