TarotAI / index.html
massimoavvisati's picture
WIP
3beb5b8
raw
history blame
3.74 kB
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Tarot Fortune Teller</title>
<style>
body {
font-family: 'Arial', sans-serif;
background-color: #1a1a2e;
color: #e0e0e0;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
padding: 20px;
box-sizing: border-box;
}
.container {
background-color: #16213e;
border-radius: 15px;
padding: 30px;
box-shadow: 0 0 20px rgba(0, 0, 0, 0.3);
text-align: center;
max-width: 500px;
width: 100%;
}
h1 {
color: #e94560;
margin-bottom: 20px;
}
textarea {
width: 100%;
height: 100px;
margin-bottom: 20px;
padding: 10px;
border-radius: 5px;
border: none;
background-color: #0f3460;
color: #e0e0e0;
resize: vertical;
}
button {
background-color: #e94560;
color: #fff;
border: none;
padding: 10px 20px;
border-radius: 5px;
cursor: pointer;
transition: background-color 0.3s;
}
button:hover {
background-color: #c73e54;
}
#prediction {
margin-top: 20px;
font-style: italic;
}
</style>
</head>
<body>
<div class="container">
<h1>Tarot Fortune Teller</h1>
<textarea id="question" placeholder="Enter your question here..."></textarea>
<button onclick="getPrediction()">Reveal Your Fortune</button>
<p id="prediction"></p>
</div>
<script type="module">
import { Client } from 'https://cdn.jsdelivr.net/npm/@gradio/client@1.5.1/+esm'
import MarkdownIt from 'https://cdn.jsdelivr.net/npm/markdown-it@14.1.0/+esm'
const md = new MarkdownIt();
function drawThreeCards() {
const majorArcana = [
"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"
];
// Shuffle the array
const shuffledDeck = majorArcana.sort(() => 0.5 - Math.random());
// Select the first three cards from the shuffled array
const selectedCards = shuffledDeck.slice(0, 3);
// Join the selected cards into a single string separated by commas
return selectedCards.join(", ");
}
window.getPrediction = async function () {
const question = document.getElementById('question').value;
const predictionElement = document.getElementById('prediction');
if (!question) {
predictionElement.textContent = "Please enter a question first.";
return;
}
predictionElement.textContent = "Consulting the cards...";
try {
const client = await Client.connect("hysts/zephyr-7b");
const result = await client.submit("/chat", {
message: `Cards: ${drawThreeCards()} User Question: ${question}`,
system_prompt: "You are an expert fortune teller capable of interpreting tarot cards giving a quick answer and a bit of interpretation in the native language of the User Question",
max_new_tokens: 512,
// temperature: 0.7,
// top_p: 0.95,
// top_k: 50,
// repetition_penalty: 1,
});
let fullResponse = '';
for await (const msg of result) {
if (msg.type === "data") {
fullResponse = msg.data[0];
predictionElement.innerHTML = md.render(fullResponse);
}
}
//predictionElement.textContent = result.data[0];
} catch (error) {
console.error('Error:', error);
predictionElement.textContent = "The cards are clouded. Please try again later.";
}
}
</script>
</body>
</html>