iamnith commited on
Commit
17d7c18
·
verified ·
1 Parent(s): fc56e6c

Feat: Initial commit to prod

Browse files
Files changed (3) hide show
  1. README.md +14 -12
  2. app.py +86 -0
  3. requirements.txt +4 -0
README.md CHANGED
@@ -1,12 +1,14 @@
1
- ---
2
- title: GhibhiGenerator
3
- emoji: 👁
4
- colorFrom: indigo
5
- colorTo: blue
6
- sdk: gradio
7
- sdk_version: 5.23.3
8
- app_file: app.py
9
- pinned: false
10
- ---
11
-
12
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
1
+ ---
2
+ title: GhibhiGenerator
3
+ emoji: 🎨
4
+ colorFrom: yellow
5
+ colorTo: purple
6
+ sdk: gradio
7
+ sdk_version: 4.38.1
8
+ app_file: app.py
9
+ pinned: false
10
+ license: agpl-3.0
11
+ short_description: Turn your images into Ghibli style!
12
+ ---
13
+
14
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
app.py ADDED
@@ -0,0 +1,86 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import random, gradio as gr
2
+ from atelier_generator import AtelierGenerator
3
+ client = AtelierGenerator(gradio=True, wm_text="GhibhiGenerator! by NithiyaShri")
4
+
5
+ gr_css = """
6
+ footer {
7
+ display: none !important;
8
+ }
9
+
10
+ .image-frame.svelte-rrgd5g img {
11
+ height: 640px;
12
+ object-fit: contain;
13
+ }
14
+
15
+ .grid-wrap.svelte-eynlr2.svelte-eynlr2 {
16
+ overflow-y: auto;
17
+ }
18
+ """
19
+
20
+ gr_thm = gr.themes.Default(
21
+ primary_hue=gr.themes.colors.rose,
22
+ secondary_hue=gr.themes.colors.rose,
23
+ neutral_hue=gr.themes.colors.zinc
24
+ )
25
+
26
+ lora_list = {
27
+ 'NithiyaShri/studio-ghibli': 'studio-ghibli',
28
+ 'NithiyaShri/anime-plus': 'anime-plus',
29
+ 'NithiyaShri/softserve-anime': 'softserve-anime'
30
+ }
31
+
32
+ # Initialize a cache dictionary outside the function
33
+ caption_cache = {}
34
+
35
+ def GhibhiGenerator(src, lora, mem, progress = gr.Progress()):
36
+ progress(0.1, "Preparing image (stage 1 of 3)...")
37
+ size, _, _ = client.size_checker(src)
38
+
39
+ # Check if the caption is already cached
40
+ if src in caption_cache:
41
+ prompt = caption_cache[src]
42
+
43
+ else:
44
+ progress(0.5, f"Processing {size} image (stage 2 of 3)...")
45
+ prompt = client.image_caption(src)
46
+ caption_cache[src] = prompt
47
+
48
+ progress(0.8, f"Rendering {size} image (stage 3 of 3)...")
49
+ result = client.image_variation(src, prompt, image_size=size, strength=0.33, lora_flux=lora_list.get(lora))
50
+
51
+ if result:
52
+ mem.insert(0, result)
53
+ return mem
54
+ else:
55
+ gr.Warning('Something went wrong! Please try again.')
56
+ return mem
57
+
58
+ with gr.Blocks(analytics_enabled=False, title='GhibhiGenerator by NithiyaShri', css=gr_css, theme=gr_thm) as demo:
59
+ gr.Markdown("## <br><center>GhibhiGenerator - Transform your images to Ghibli style!")
60
+ gr.Markdown("<center>Copyright (C) 2025 Nithiya Shri. All rights reserved")
61
+
62
+ with gr.Row():
63
+ with gr.Column():
64
+ with gr.Column(variant='panel'):
65
+ gr.Markdown("## <center>📸 Upload Your Image!")
66
+ src = gr.Image(type='filepath', label='Source Image', height=640, sources=['upload'])
67
+
68
+ with gr.Column(variant='panel'):
69
+ lst = gr.Radio(choices=lora_list.keys(), value=list(lora_list.keys())[0], label='Select a style:')
70
+ run = gr.Button("GhibhiGenerator!", variant='stop')
71
+
72
+ with gr.Column():
73
+ with gr.Column(variant='panel'):
74
+ gr.Markdown("## <center>🎨 GhibhiGenerator It!")
75
+ res = gr.Gallery(label='Result Image', height=814.19)
76
+ mem = gr.State([])
77
+
78
+ gr.Markdown("<br><center>Disclaimer: Due to huge demand, image processing might take longer than expected.<br>")
79
+
80
+ run.click(
81
+ inputs=[src, lst, mem],
82
+ outputs=res,
83
+ fn=GhibhiGenerator
84
+ )
85
+
86
+ demo.launch(inbrowser=True)
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ gradio==4.38.1
2
+ fastapi==0.112.4
3
+ pydantic==2.10.6
4
+ atelier-generator