File size: 2,810 Bytes
68e9609
857d94b
c5d56ba
99ac7e3
68e9609
e338f7b
 
 
 
 
99ac7e3
e338f7b
 
 
 
 
d3811c5
9f3ddf9
8061c4b
 
 
 
 
 
 
 
e338f7b
8061c4b
 
e338f7b
857d94b
32a351c
857d94b
8061c4b
e338f7b
 
 
 
 
8061c4b
 
e338f7b
857d94b
8061c4b
857d94b
0daefef
 
 
 
 
 
 
 
 
 
 
 
 
 
68e9609
0daefef
 
 
 
 
 
 
 
 
 
 
 
 
 
99ac7e3
0daefef
 
99ac7e3
d305a6e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
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}")
    
    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
        
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)
    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")  
    
    outputBox=gr.Textbox(label="The character",show_label=True)

    rollButt.click(stat, inputs=[dice,gr.Number(value=6, visible=False,precision=0)],outputs=[wisBox,charBox,strBox,intBox,dexBox,conBox])
statBlock.launch()