File size: 6,469 Bytes
e1af8ca
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
import gradio as gr
import random
import time
from datetime import datetime

# Custom theme for the manga/anime application
custom_theme = gr.themes.Soft(
    primary_hue="pink",
    secondary_hue="purple",
    neutral_hue="slate",
    font=gr.themes.GoogleFont("Inter"),
    text_size="lg",
    spacing_size="lg",
    radius_size="md"
).set(
    button_primary_background_fill="*primary_600",
    button_primary_background_fill_hover="*primary_700",
    block_title_text_weight="600",
)

def get_random_manga_recommendation():
    """Generate a random manga recommendation"""
    manga_list = [
        "One Piece",
        "Naruto",
        "Attack on Titan",
        "Death Note",
        "Fullmetal Alchemist",
        "Dragon Ball",
        "Bleach",
        "Tokyo Revengers",
        "Demon Slayer",
        "Jujutsu Kaisen"
    ]
    return random.choice(manga_list)

def get_manga_info(manga_name):
    """Get information about a specific manga"""
    manga_data = {
        "One Piece": {
            "author": "Eiichiro Oda",
            "genre": "Adventure, Fantasy",
            "status": "Ongoing",
            "chapters": "1000+"
        },
        "Naruto": {
            "author": "Masashi Kishimoto",
            "genre": "Action, Adventure",
            "status": "Completed",
            "chapters": "700"
        },
        "Attack on Titan": {
            "author": "Hajime Isayama",
            "genre": "Dark Fantasy, Action",
            "status": "Completed",
            "chapters": "139"
        }
    }

    if manga_name in manga_data:
        info = manga_data[manga_name]
        return f"""
        **{manga_name}**
        - Author: {info['author']}
        - Genre: {info['genre']}
        - Status: {info['status']}
        - Chapters: {info['chapters']}
        """
    else:
        return f"Sorry, I don't have information about {manga_name}."

def search_manga(query):
    """Search for manga based on query"""
    # Simulate search delay
    time.sleep(1)

    # Simple search logic
    all_manga = [
        "One Piece", "Naruto", "Attack on Titan", "Death Note",
        "Fullmetal Alchemist", "Dragon Ball", "Bleach",
        "Tokyo Revengers", "Demon Slayer", "Jujutsu Kaisen"
    ]

    results = [manga for manga in all_manga if query.lower() in manga.lower()]

    if results:
        return "\n".join([f"- {manga}" for manga in results])
    else:
        return "No manga found matching your search."

def get_current_time():
    """Get current time for the timer demo"""
    return datetime.now().strftime("%H:%M:%S")

def generate_manga_quote():
    """Generate a random manga quote"""
    quotes = [
        "The world isn't perfect. But it's there for us, doing the best it can... that's what makes it so damn beautiful.",
        "Power comes in response to a need, not a desire.",
        "If you don't take risks, you can't create a future!",
        "Sometimes you have to walk the path alone to truly find yourself.",
        "The only thing we're allowed to do is believe that we won't regret the choice we made."
    ]
    return random.choice(quotes)

# Create the Gradio interface
with gr.Blocks() as demo:
    gr.Markdown("""
    # 🐠 MangaVerse - Your Manga Companion
    Explore the world of manga with our interactive tools!
    """)

    with gr.Tabs():
        # Tab 1: Manga Recommendations
        with gr.Tab("Manga Recommendations"):
            gr.Markdown("### Get Random Manga Recommendations")
            with gr.Row():
                recommend_btn = gr.Button("🎲 Get Random Manga", variant="primary")
                manga_output = gr.Textbox(label="Recommended Manga", interactive=False)

            recommend_btn.click(
                fn=get_random_manga_recommendation,
                outputs=manga_output,
                api_visibility="public"
            )

        # Tab 2: Manga Search
        with gr.Tab("Manga Search"):
            gr.Markdown("### Search for Manga")
            with gr.Row():
                search_input = gr.Textbox(label="Search Query", placeholder="Enter manga name...")
                search_btn = gr.Button("πŸ” Search", variant="primary")
                search_output = gr.Textbox(label="Search Results", interactive=False)

            search_btn.click(
                fn=search_manga,
                inputs=search_input,
                outputs=search_output,
                api_visibility="public"
            )

        # Tab 3: Manga Info
        with gr.Tab("Manga Information"):
            gr.Markdown("### Get Manga Information")
            with gr.Row():
                manga_dropdown = gr.Dropdown(
                    choices=["One Piece", "Naruto", "Attack on Titan"],
                    label="Select Manga",
                    value="One Piece"
                )
                info_btn = gr.Button("πŸ“– Get Info", variant="primary")
                info_output = gr.Markdown()

            info_btn.click(
                fn=get_manga_info,
                inputs=manga_dropdown,
                outputs=info_output,
                api_visibility="public"
            )

        # Tab 4: Manga Quotes
        with gr.Tab("Manga Quotes"):
            gr.Markdown("### Get Inspiring Manga Quotes")
            with gr.Row():
                quote_btn = gr.Button("πŸ’¬ Get Quote", variant="primary")
                quote_output = gr.Textbox(label="Manga Quote", interactive=False, lines=3)

            quote_btn.click(
                fn=generate_manga_quote,
                outputs=quote_output,
                api_visibility="public"
            )

        # Tab 5: Timer Demo
        with gr.Tab("Timer Demo"):
            gr.Markdown("### Current Time")
            timer = gr.Timer(every=1)
            time_output = gr.Textbox(label="Current Time", interactive=False)

            timer.tick(
                fn=get_current_time,
                outputs=time_output,
                api_visibility="private"
            )

    # Footer with Built with anycoder
    gr.Markdown("""
    ---

    **Built with [anycoder](https://huggingface.co/spaces/akhaliq/anycoder)** | 🐠 MangaVerse 2023
    """)

# Launch the app with Gradio 6 syntax
demo.launch(
    theme=custom_theme,
    footer_links=[
        {"label": "Built with anycoder", "url": "https://huggingface.co/spaces/akhaliq/anycoder"},
        {"label": "Gradio Docs", "url": "https://gradio.app/docs"}
    ],
    share=False,
    show_error=True
)