-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathReadergui.py
117 lines (95 loc) · 3.19 KB
/
Readergui.py
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
import random
import openai
import os
import tkinter as tk
from tkinter import messagebox
class TarotCard:
def __init__(self, name):
self.name = name
class TarotDeck:
def __init__(self):
self.cards = []
self.load_cards()
def load_cards(self):
major_arcana = [
"The Fool",
"The Magician",
"The High Priestess",
"The Empress",
"The Emperor",
"The Hierophant",
"The Lovers",
"The Chariot",
"Strength",
"The Hermit",
"Wheel of Fortune",
"Justice",
"The Hanged Man",
"Death",
"Temperance",
"The Devil",
"The Tower",
"The Star",
"The Moon",
"The Sun",
"Judgement",
"The World",
]
for card_name in major_arcana:
self.cards.append(TarotCard(card_name))
def draw_card(self):
return random.choice(self.cards)
class TarotReader:
def __init__(self):
self.deck = TarotDeck()
def draw_cards(self, count=1):
cards = []
for _ in range(count):
card = self.deck.draw_card()
cards.append(card)
self.deck.cards.remove(card)
return cards
def interpret_cards(self, cards):
interpretations = []
for card in cards:
upright = random.choice([True, False])
orientation = "Upright" if upright else "Reversed"
prompt = f"Provide the {orientation.lower()} meaning of the {card.name} tarot card."
response = openai.Completion.create(
engine="text-davinci-002",
prompt=prompt,
max_tokens=50,
n=1,
stop=None,
temperature=0.7,
)
meaning = response.choices[0].text.strip()
interpretations.append(f"{card.name} ({orientation}): {meaning}")
return interpretations
def gui_main():
def draw_and_interpret():
card_count = int(card_count_var.get())
reader = TarotReader()
cards = reader.draw_cards(card_count)
interpretations = reader.interpret_cards(cards)
interpretation_text = "\nYour Tarot reading:\n"
for interpretation in interpretations:
interpretation_text += f"{interpretation}\n"
messagebox.showinfo("Tarot Reading", interpretation_text)
root = tk.Tk()
root.title("AI Tarot Reader based on ChatGPT")
tk.Label(root, text="Welcome to the AI Tarot Reader based on ChatGPT!").pack()
tk.Label(root, text="Please choose a number of cards to draw (1-3):").pack()
card_count_var = tk.StringVar(root)
card_count_var.set("1")
tk.OptionMenu(root, card_count_var, "1", "2", "3").pack()
draw_button = tk.Button(root, text="Draw Cards", command=draw_and_interpret)
draw_button.pack()
root.mainloop()
if __name__ == "__main__":
openai.api_key = "yourKEY"
if not openai.api_key:
print("Error: API key not found. Please set the OPENAI_API_KEY environment variable.")
input("Press Enter to exit...")
else:
gui_main()