import gradio as gr import openai import os import random from dotenv import load_dotenv from openai import OpenAI load_dotenv() openai.api_key = os.getenv('OPENAI_API_KEY') print(openai.api_key) print (os.environ.get("OPENAI_API_KEY")) client = openai.OpenAI(organization='org-eiNl8e4nk93VLQFDb4EBz9JG') #openai.api_key = os.environ['openai'] #for huggingface i think #generates an AI description of your character def describe(names,wis,char,str,int,dex,con): print(f"hi{names}") if (wis==0) : print(f"set some stats or roll random") exit prom=f"We're generating Dungeons and Dragons characters for a new campaign, and we need a brief character description, including race" prom+=f" and class. The character's name is {names} with the following stats: Wisdom: {wis},Charisma:{char},Strength:{str}," prom+=f"Intelligence:{int},Dexterity:{dex},Constitution:{con}. Describe the character, and then, separated by $$$ give us the " prom+=f"character's interesting backstory." completion = client.completions.create( model='gpt-3.5-turbo-instruct', prompt=prom, max_tokens=510, temperature=0.77, frequency_penalty=0.2, presence_penalty= 0.25) result =completion.choices[0].text #print(dict(completion).get('usage')) #print(completion.model_dump_json(indent=2)) if not result : result = "Could you be any more boring?" return result #generates an AI description of your character def makeName(): prom=f"We're generating Dungeons and Dragons characters for a new campaign, and we need a name." prom+=f" Please imagine and give me just a character name for the player to use." completion = client.completions.create( model='gpt-3.5-turbo-instruct', prompt=prom, max_tokens=50, temperature=0.77, frequency_penalty=0.2, presence_penalty= 0.25) result =completion.choices[0].text #print(dict(completion).get('usage')) #print(completion.model_dump_json(indent=2)) if not result : result = "The Doctor" return result def stat( ndice, dicerank): # return ndice + dicerank answer=[] for x in range(6) : results = [ # Generate ndice numbers between [1,dice_rank] random.randint(1, dicerank) for n in range(ndice) ] lowest = min(results) # Find the lowest roll among the results results.remove(lowest) # Remove the first instance of that lowest roll answer.append(sum(results)) # Return the sum of the remaining results. return answer with gr.Blocks() as statBlock: gr.Markdown("Your characters stats") nameBox = gr.Textbox(label="Your DND character",show_label=True) nameButt = gr.Button(value="Random Name") wisBox = gr.Number(label="Wisdom",show_label=True,precision=0,minimum=1,maximum=18) charBox = gr.Number(label="Charisma",show_label=True,precision=0) strBox =gr.Number(label="Strength",show_label=True,precision=0) intBox =gr.Number(label="Intelligence",show_label=True,precision=0) dexBox =gr.Number(label="Dexterity",show_label=True,precision=0) conBox =gr.Number(label="Constitution",show_label=True,precision=0) dice = gr.Number(value=4,precision=0,visible=False) dice.visible = False rollButt = gr.Button(value="Roll Stats") describeButt = gr.Button(value="Generate Description") outputBox=gr.Textbox(label="The character",show_label=True) nameButt.click(makeName,inputs=[],outputs=[nameBox]) rollButt.click(stat, inputs=[dice,gr.Number(value=6, visible=False,precision=0)],outputs=[wisBox,charBox,strBox,intBox,dexBox,conBox]) describeButt.click(describe, outputs=[outputBox],inputs=[nameBox,wisBox,charBox,strBox,intBox,dexBox,conBox]) statBlock.launch()