Jensin commited on
Commit
e1af8ca
ยท
verified ยท
1 Parent(s): 970ab22

Update app.py from anycoder

Browse files
Files changed (1) hide show
  1. app.py +202 -0
app.py ADDED
@@ -0,0 +1,202 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import random
3
+ import time
4
+ from datetime import datetime
5
+
6
+ # Custom theme for the manga/anime application
7
+ custom_theme = gr.themes.Soft(
8
+ primary_hue="pink",
9
+ secondary_hue="purple",
10
+ neutral_hue="slate",
11
+ font=gr.themes.GoogleFont("Inter"),
12
+ text_size="lg",
13
+ spacing_size="lg",
14
+ radius_size="md"
15
+ ).set(
16
+ button_primary_background_fill="*primary_600",
17
+ button_primary_background_fill_hover="*primary_700",
18
+ block_title_text_weight="600",
19
+ )
20
+
21
+ def get_random_manga_recommendation():
22
+ """Generate a random manga recommendation"""
23
+ manga_list = [
24
+ "One Piece",
25
+ "Naruto",
26
+ "Attack on Titan",
27
+ "Death Note",
28
+ "Fullmetal Alchemist",
29
+ "Dragon Ball",
30
+ "Bleach",
31
+ "Tokyo Revengers",
32
+ "Demon Slayer",
33
+ "Jujutsu Kaisen"
34
+ ]
35
+ return random.choice(manga_list)
36
+
37
+ def get_manga_info(manga_name):
38
+ """Get information about a specific manga"""
39
+ manga_data = {
40
+ "One Piece": {
41
+ "author": "Eiichiro Oda",
42
+ "genre": "Adventure, Fantasy",
43
+ "status": "Ongoing",
44
+ "chapters": "1000+"
45
+ },
46
+ "Naruto": {
47
+ "author": "Masashi Kishimoto",
48
+ "genre": "Action, Adventure",
49
+ "status": "Completed",
50
+ "chapters": "700"
51
+ },
52
+ "Attack on Titan": {
53
+ "author": "Hajime Isayama",
54
+ "genre": "Dark Fantasy, Action",
55
+ "status": "Completed",
56
+ "chapters": "139"
57
+ }
58
+ }
59
+
60
+ if manga_name in manga_data:
61
+ info = manga_data[manga_name]
62
+ return f"""
63
+ **{manga_name}**
64
+ - Author: {info['author']}
65
+ - Genre: {info['genre']}
66
+ - Status: {info['status']}
67
+ - Chapters: {info['chapters']}
68
+ """
69
+ else:
70
+ return f"Sorry, I don't have information about {manga_name}."
71
+
72
+ def search_manga(query):
73
+ """Search for manga based on query"""
74
+ # Simulate search delay
75
+ time.sleep(1)
76
+
77
+ # Simple search logic
78
+ all_manga = [
79
+ "One Piece", "Naruto", "Attack on Titan", "Death Note",
80
+ "Fullmetal Alchemist", "Dragon Ball", "Bleach",
81
+ "Tokyo Revengers", "Demon Slayer", "Jujutsu Kaisen"
82
+ ]
83
+
84
+ results = [manga for manga in all_manga if query.lower() in manga.lower()]
85
+
86
+ if results:
87
+ return "\n".join([f"- {manga}" for manga in results])
88
+ else:
89
+ return "No manga found matching your search."
90
+
91
+ def get_current_time():
92
+ """Get current time for the timer demo"""
93
+ return datetime.now().strftime("%H:%M:%S")
94
+
95
+ def generate_manga_quote():
96
+ """Generate a random manga quote"""
97
+ quotes = [
98
+ "The world isn't perfect. But it's there for us, doing the best it can... that's what makes it so damn beautiful.",
99
+ "Power comes in response to a need, not a desire.",
100
+ "If you don't take risks, you can't create a future!",
101
+ "Sometimes you have to walk the path alone to truly find yourself.",
102
+ "The only thing we're allowed to do is believe that we won't regret the choice we made."
103
+ ]
104
+ return random.choice(quotes)
105
+
106
+ # Create the Gradio interface
107
+ with gr.Blocks() as demo:
108
+ gr.Markdown("""
109
+ # ๐Ÿ  MangaVerse - Your Manga Companion
110
+ Explore the world of manga with our interactive tools!
111
+ """)
112
+
113
+ with gr.Tabs():
114
+ # Tab 1: Manga Recommendations
115
+ with gr.Tab("Manga Recommendations"):
116
+ gr.Markdown("### Get Random Manga Recommendations")
117
+ with gr.Row():
118
+ recommend_btn = gr.Button("๐ŸŽฒ Get Random Manga", variant="primary")
119
+ manga_output = gr.Textbox(label="Recommended Manga", interactive=False)
120
+
121
+ recommend_btn.click(
122
+ fn=get_random_manga_recommendation,
123
+ outputs=manga_output,
124
+ api_visibility="public"
125
+ )
126
+
127
+ # Tab 2: Manga Search
128
+ with gr.Tab("Manga Search"):
129
+ gr.Markdown("### Search for Manga")
130
+ with gr.Row():
131
+ search_input = gr.Textbox(label="Search Query", placeholder="Enter manga name...")
132
+ search_btn = gr.Button("๐Ÿ” Search", variant="primary")
133
+ search_output = gr.Textbox(label="Search Results", interactive=False)
134
+
135
+ search_btn.click(
136
+ fn=search_manga,
137
+ inputs=search_input,
138
+ outputs=search_output,
139
+ api_visibility="public"
140
+ )
141
+
142
+ # Tab 3: Manga Info
143
+ with gr.Tab("Manga Information"):
144
+ gr.Markdown("### Get Manga Information")
145
+ with gr.Row():
146
+ manga_dropdown = gr.Dropdown(
147
+ choices=["One Piece", "Naruto", "Attack on Titan"],
148
+ label="Select Manga",
149
+ value="One Piece"
150
+ )
151
+ info_btn = gr.Button("๐Ÿ“– Get Info", variant="primary")
152
+ info_output = gr.Markdown()
153
+
154
+ info_btn.click(
155
+ fn=get_manga_info,
156
+ inputs=manga_dropdown,
157
+ outputs=info_output,
158
+ api_visibility="public"
159
+ )
160
+
161
+ # Tab 4: Manga Quotes
162
+ with gr.Tab("Manga Quotes"):
163
+ gr.Markdown("### Get Inspiring Manga Quotes")
164
+ with gr.Row():
165
+ quote_btn = gr.Button("๐Ÿ’ฌ Get Quote", variant="primary")
166
+ quote_output = gr.Textbox(label="Manga Quote", interactive=False, lines=3)
167
+
168
+ quote_btn.click(
169
+ fn=generate_manga_quote,
170
+ outputs=quote_output,
171
+ api_visibility="public"
172
+ )
173
+
174
+ # Tab 5: Timer Demo
175
+ with gr.Tab("Timer Demo"):
176
+ gr.Markdown("### Current Time")
177
+ timer = gr.Timer(every=1)
178
+ time_output = gr.Textbox(label="Current Time", interactive=False)
179
+
180
+ timer.tick(
181
+ fn=get_current_time,
182
+ outputs=time_output,
183
+ api_visibility="private"
184
+ )
185
+
186
+ # Footer with Built with anycoder
187
+ gr.Markdown("""
188
+ ---
189
+
190
+ **Built with [anycoder](https://huggingface.co/spaces/akhaliq/anycoder)** | ๐Ÿ  MangaVerse 2023
191
+ """)
192
+
193
+ # Launch the app with Gradio 6 syntax
194
+ demo.launch(
195
+ theme=custom_theme,
196
+ footer_links=[
197
+ {"label": "Built with anycoder", "url": "https://huggingface.co/spaces/akhaliq/anycoder"},
198
+ {"label": "Gradio Docs", "url": "https://gradio.app/docs"}
199
+ ],
200
+ share=False,
201
+ show_error=True
202
+ )