Spaces:
Build error
Build error
| 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 | |
| ) |