Spaces:
Build error
Build error
| 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(""" | |
| <h1><center>Aitrium AI Tech Demo: Anuska</center></h1> | |
| <div style="display: flex;"> | |
| <div style="flex: 1; text-align: center; background-color: #cccccc; padding: 10px; border-right: 5px solid white;"> | |
| <strong>💬 Examples:</strong> | |
| <hr style="border-top: 5px solid white; margin: 0px;"> | |
| <br><strong>You can talk to Anuska naturally:</strong> | |
| <br>"Hey Anuska!" | |
| <br>"Hello Anuska, how are you?" | |
| <br>"Anuska, what have you done today?" | |
| <br>"What have you been up to today?" | |
| <br>"What's new with you?" | |
| </div> | |
| <div style="flex: 1; text-align: center; background-color: #cccccc; padding: 10px; border-right: 5px solid white;"> | |
| <strong>🤖 Capabilities:</strong> | |
| <hr style="border-top: 5px solid white; margin: 0px;"> | |
| <br><strong>Anuska isn't like most chatbots:</strong> | |
| <br>Anuska remembers the conversation she is having. | |
| <br>She has her own personality, character and memory. | |
| <br>She is designed to be a companion. | |
| <br>She understands what she is saying. | |
| <br>She is capable of becoming disinterested. | |
| </div> | |
| <div style="flex: 1; text-align: center; background-color: #cccccc; padding: 10px;"> | |
| <strong>⚠️ Limitations:</strong> | |
| <hr style="border-top: 5px solid white; margin: 0px;"> | |
| <br><strong>Anuska, like other large language models may:</strong> | |
| <br>Sometimes give inaccurate information | |
| <br>Sometimes generate harmful or biased content | |
| <br>Generate inappropriate content | |
| <br>Sometimes hallucinate or generate information about herself | |
| <br>Her world knowledge may be limited or out of date. | |
| </div> | |
| </div> | |
| """) | |
| #demo = gr.Interface(fn=AI, inputs="text", outputs="text") | |
| demo = gr.Interface(fn=AI, inputs="text", outputs="text",) | |
| gr.Markdown(""" | |
| <style> | |
| .disclaimer { | |
| background-color: yellow; | |
| color: black; | |
| padding: 10px; | |
| font-family: 'Roboto', sans-serif; | |
| text-align: center; | |
| font-size: 1em; | |
| } | |
| </style> | |
| <div class="disclaimer"> | |
| <strong>Disclaimer:</strong><br>By using this web app, you understand and agree that all conversations within the app will be logged, monitored, and analyzed for the purposes of improving the service and ensuring compliance with legal and ethical guidelines. Any personal information collected will be kept confidential and used in accordance with our privacy policy. Aitrium is not responsible for the content generated by this app. The app is powered by a language model and its outputs are based on the patterns and associations it has learned from the data it was trained on. Aitrium cannot guarantee the accuracy, completeness, or suitability of any information generated by Anuska. | |
| </div> | |
| """) | |
| block.launch() |