Spaces:
Running
Running
File size: 4,042 Bytes
3b38e07 132cb66 3b38e07 132cb66 3b38e07 132cb66 15c6b6b 868e142 15c6b6b 132cb66 868e142 132cb66 15c6b6b 132cb66 fc534ec 132cb66 15c6b6b 132cb66 15c6b6b 132cb66 15c6b6b 132cb66 15c6b6b 132cb66 15c6b6b 132cb66 868e142 15c6b6b 132cb66 868e142 15c6b6b 132cb66 15c6b6b 132cb66 3b38e07 15c6b6b 132cb66 868e142 15c6b6b 132cb66 868e142 15c6b6b 132cb66 |
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 118 119 120 121 122 |
import os
import streamlit as st
import yaml
from PIL import Image
from modules.llm.card_interpreter import CardInterpreter
from modules.tarot.card import TarotDeck
from modules.utils.commom import CardReadingMethod, label4method
from scripts.get_cards import get_cards
base_dir = os.path.dirname(os.path.abspath(__file__))
data_dir = os.path.join(base_dir, "data")
json_file = os.path.join(data_dir, "tarot-images.json")
if 'initialized' not in st.session_state:
get_cards()
st.session_state.initialized = True
# Initialize deck and interpreter
if 'deck' not in st.session_state:
deck = TarotDeck()
deck.get_cards()
st.session_state.deck = deck
if 'interpreter' not in st.session_state:
interpreter = CardInterpreter()
st.session_state.interpreter = interpreter
st.set_page_config(page_title="Tarot Reading", page_icon="๐ฎ", layout="centered")
st.title("๐ฎ Tarot Reading")
# Secret configurations
with st.sidebar:
with st.expander("Settings", expanded=False, icon="โ๏ธ"):
reversed_prob = st.slider(
"Probability of reversed cards",
min_value=0.0,
max_value=1.0,
value=yaml.safe_load(open("config.yaml"))["reverse_probability"],
step=0.1,
help="Probability of a card appearing reversed (0.0 to 1.0)",
)
# User interface texts
welcome_text = "### Welcome to your Tarot Reading"
instructions_text = (
"Please select a reading method and provide a context for your consultation."
)
method_text = "Choose your reading method:"
context_text = "What would you like to know about? (Optional)"
context_placeholder = "Ex: I need guidance about finding my life purpose..."
draw_button = "Draw Cards"
spinner_texts = {
"shuffle": "๐ฎ Shuffling the cards with mystical energy...",
"channel": "โจ Channeling the energies of the universe...",
"reveal": "๐ Revealing the secrets of destiny...",
"consult": "๐งโโ๏ธ Consulting ancient wisdom...",
"cards": "### Your Cards:",
"reading": "### Your Reading:",
"default_context": "General daily reading",
}
# Display welcome message and instructions
st.markdown(welcome_text)
st.markdown(instructions_text)
# Reading method selection
method = st.selectbox(
method_text,
[
CardReadingMethod.PAST_PRESENT_FUTURE.value,
CardReadingMethod.CELTIC_CROSS.value,
CardReadingMethod.HAND_OF_ERIS.value,
],
)
# Reading context input
context = st.text_area(context_text, placeholder=context_placeholder)
if st.button(draw_button):
# Shuffle and draw cards
with st.spinner(spinner_texts["shuffle"]):
st.session_state.deck.shuffle(reversed_prob)
with st.spinner(spinner_texts["channel"]):
cards = st.session_state.deck.draw(CardReadingMethod(method))
# Display cards
st.markdown(spinner_texts["cards"])
cols = st.columns(len(cards))
for idx, (card, col) in enumerate(zip(cards, cols)):
with col:
with st.spinner(spinner_texts["reveal"]):
if card.reversed:
img = Image.open(card.image_pth).rotate(180)
st.image(
img,
caption=f"{label4method[CardReadingMethod(method)][idx]}: {card.name} (Reversed)",
)
else:
st.image(
card.image_pth,
caption=f"{label4method[CardReadingMethod(method)][idx]}: {card.name}",
)
# Generate and display interpretation
with st.spinner(spinner_texts["consult"]):
if context:
interpretation = st.session_state.interpreter.generate_interpretation(
cards, context, CardReadingMethod(method)
)
else:
interpretation = st.session_state.interpreter.generate_interpretation(
cards, None, CardReadingMethod(method)
)
st.markdown(spinner_texts["reading"])
st.write(interpretation)
|