File size: 2,509 Bytes
95816f5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
fee804f
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
import gradio as gr
import requests
import random
from typing import Union


# API Configuration
API_BASE_URL = "https://tarotapi.dev/api/v1"

def get_tarot_reading(question: str, num_cards: float) -> str:
    """Get a complete tarot reading"""
    if not question or not question.strip():
        return "Please enter a question for your tarot reading."
    
    try:
        # Convert float to int for API call
        card_count = int(num_cards)
        
        # Make API request
        response = requests.get(f"{API_BASE_URL}/cards/random?n={card_count}")
        
        if response.status_code != 200:
            return f"API Error: Unable to fetch cards (Status: {response.status_code})"
        
        data = response.json()
        
        if 'cards' not in data or not data['cards']:
            return "Error: No cards returned from the API"
        
        # Build the reading
        reading = "🔮 Your Tarot Reading 🔮\n\n"
        reading += f"Question: {question}\n\n"
        
        for i, card in enumerate(data['cards'], 1):
            name = card.get('name', 'Unknown Card')
            orientation = random.choice(['Upright', 'Reversed'])
            
            reading += f"Card {i}: {name} ({orientation})\n"
            
            # Add meaning
            if orientation == 'Upright':
                meaning = card.get('meaning_up', 'No meaning available')
            else:
                meaning = card.get('meaning_rev', 'No meaning available')
            
            reading += f"Meaning: {meaning}\n\n"
        
        return reading
        
    except requests.exceptions.RequestException as e:
        return f"Network Error: {str(e)}"
    except Exception as e:
        return f"Error: {str(e)}"

# Create the interface with explicit types
demo = gr.Interface(
    fn=get_tarot_reading,
    inputs=[
        gr.Textbox(
            label="What would you like to know?",
            placeholder="Enter your question here...",
            lines=2,
            value=""
        ),
        gr.Slider(
            minimum=1,
            maximum=5,
            value=3,
            step=1,
            label="Number of cards to draw"
        )
    ],
    outputs=gr.Textbox(
        label="Your Reading",
        lines=15,
        value=""
    ),
    title="🔮 Tarot MCP Server 🔮",
    description="A simple MCP server for tarot readings using the Tarot API",
    allow_flagging="never"
)

if __name__ == "__main__":
    demo.launch(mcp_server=True)