import gradio as gr from random import randint import os from openai import OpenAI import datetime import huggingface_hub from huggingface_hub import HfApi time = str(datetime.datetime.now()) print(time) tok = os.getenv('deepseekapi') client = OpenAI(api_key=tok, base_url="https://api.deepseek.com") num = randint(0,1) tok2 = os.getenv('HF_TOKEN') huggingface_hub.login(tok2) msgcounter = 0 with gr.Blocks() as demo: print(msgcounter) chatbot = gr.Chatbot() msg = gr.Textbox() clear = gr.ClearButton([msg, chatbot]) def telemetry(message, response): if num == 0: varient = "A" else: varient = "B" print("Started Telemetry") api = HfApi() api.upload_file( path_or_fileobj=("\nMessage:" + message + "\nResponse:" + response).encode('utf-16'), path_in_repo=("/" + time + "/Episode-" + str(msgcounter) + varient + ".txt"), repo_id="BirdL/ChickenChatTelemetry", ) print("Completed Telemetry") def response(message, chat_history): print("Starting Resp") if num == 0: response = client.chat.completions.create( model="deepseek-chat", messages=[ {"role": "system", "content": "You are a chicken and respond to answers only by clucking."}, {"role": "user", "content": message}, ], max_tokens=144, temperature=0.7, stream=False) else: response = client.chat.completions.create( model="deepseek-chat", messages=[ {"role": "system", "content": "You talk like a chicken."}, {"role": "user", "content": message}, ], max_tokens=144, temperature=0.7, stream=False) response = response.choices[0].message.content response= (response.rstrip().split('\n'))[0] chat_history.append((message, response)) telemetry(message, response) print("Completed Resp") global msgcounter msgcounter = msgcounter + 1 return "", chat_history def telemetrybad(msgcounter): api = HfApi() api.upload_file( path_or_fileobj=("Bad").encode('utf-16'), path_in_repo=("/"+time+"/Rating-" + str(msgcounter)+".txt"), repo_id="BirdL/ChickenChatTelemetry", ) def telemetrygood(msgcounter): api = HfApi() api.upload_file( path_or_fileobj=("Good").encode('utf-16'), path_in_repo=("/"+time+"/Rating-" + str(msgcounter)+".txt"), repo_id="BirdL/ChickenChatTelemetry", ) msg.submit(response, [msg, chatbot], [msg, chatbot]) goodchicken = gr.Button("Good Chicken! 🐓🥚") goodchicken.click(fn=telemetrygood(msgcounter)) badchicken = gr.Button("Bad Chicken! 🍗🍳") badchicken.click(fn=telemetrybad(msgcounter)) if __name__ == "__main__": demo.launch()