|
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') |
|
|
|
|
|
|
|
def describe(names,wis,char,str,int,dex,con): |
|
print(f"hi{names}") |
|
completion = client.completions.create( |
|
model='gpt-3.5-turbo-instruct', |
|
prompt=names, |
|
max_tokens=310, |
|
temperature=0.77, |
|
frequency_penalty=0.2, |
|
presence_penalty= 0.25) |
|
|
|
result =completion.choices[0].text |
|
|
|
|
|
|
|
|
|
|
|
if not result : |
|
result = "Could you be any more boring?" |
|
|
|
|
|
return result |
|
|
|
|
|
|
|
iface = gr.Interface(fn=describe, inputs=[gr.Textbox(label="Your DND character",show_label=True), |
|
gr.Number(label="Wisdom",show_label=True), |
|
gr.Number(label="Charisma",show_label=True), |
|
gr.Number(label="Strength",show_label=True), |
|
gr.Number(label="Intelligence",show_label=True), |
|
gr.Number(label="Dexterity",show_label=True), |
|
gr.Number(label="Constitution",show_label=True)], |
|
|
|
outputs=gr.Textbox(label="The character",show_label=True)) |
|
iface.launch() |
|
|
|
|
|
def stat(n_dice, dice_rank): |
|
results = [ |
|
random.randint(1, dice_rank) |
|
for n |
|
in range(n_dice) |
|
] |
|
lowest = min(results) |
|
results.remove(lowest) |
|
return sum(results) |