import cohere import gradio as gr import os api_key=os.environ.get("api-key") shade=os.environ.get("shade") co = cohere.Client(api_key) config=shade zero = config Counter = 0 Counters = "" origin = "" slash = "" newprompt = "" import random from datetime import date # specify the directory to save the file in #Gradient Directory directory = '/home/user/app/' #Google Colab Directory #directory = os.getcwd() ## generate a random number rand_num = random.randint(1, 1000000) # get the current date today = date.today() # format the date as a string date_str = today.strftime("%Y-%m-%d") # create the file name file_name = f'conversation_{rand_num}_{date_str}.txt' # create the full file path file_path = os.path.join(directory, file_name) # write some sample content to the file #with open(file_path, 'w') as f: # f.write('Sample notes for the day') count = 0 mood = "nice" def AI(userdata): global directory global rand_num global today global date_str global file_name global file_path global count global co global config global zero global Counter global Counters global origin global slash global newprompt with open(file_path, 'a') as f: f.write('\nUser: '+userdata) zero = zero+"\nUser:"+userdata+"\nAnuska:" #response = co.generate(model='xlarge', prompt=zero, max_tokens=512, temperature = 0.7, p=0.6 , k = 20, frequency_penalty=0.58, stop_sequences=["\n"]) # Try to generate a response #response = co.generate(model='xlarge', prompt=zero, max_tokens=512, temperature = 0.7, p=0.6 , k = 20, frequency_penalty=0.58, stop_sequences=["\n"]) response = co.generate(model='xlarge', prompt=zero, max_tokens=512, temperature = 0.5, p=0.4 , k = 10, frequency_penalty=0.58, stop_sequences=["\n"]) # check if response is empty if response=="": # rerun the query #response = co.generate(model='xlarge', prompt=zero, max_tokens=512, temperature = 0.7, p=0.6 , k = 20, frequency_penalty=0.58, stop_sequences=["\n"]) response = co.generate(model='xlarge', prompt=zero, max_tokens=512, temperature = 0.5, p=0.4 , k = 10, frequency_penalty=0.58, stop_sequences=["\n"]) one = format(response.generations[0].text) two = one.rsplit("\n")[0] if two=="": two = "Huh?" Counter = len(zero) Counters = str(Counter) if Counter > 2100: origin=config slash = zero[1500:] newprompt=origin+slash zero=newprompt zero=zero+two count = count + 1 with open(file_path, 'a') as f: f.write('\nAnuska: '+two) return two block = gr.Blocks() with block: gr.Markdown("""