Abhaykoul commited on
Commit
ebb03f1
·
verified ·
1 Parent(s): 479454e

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +137 -0
app.py ADDED
@@ -0,0 +1,137 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import requests
3
+ import io
4
+ import random
5
+ import os
6
+ from PIL import Image
7
+
8
+ # List of available models
9
+ list_models = [
10
+ "PixelCraft"
11
+ ]
12
+
13
+ # Function to generate images from text
14
+ def generate_txt2img(current_model, prompt, is_negative=False, image_style="None style", steps=50, cfg_scale=7, seed=None):
15
+ API_URL = "https://api-inference.huggingface.co/models/OEvortex/HelpingAI-PixelCraft"
16
+ headers = {"Authorization": "Bearer {API}"}
17
+
18
+ base_payload = {
19
+ "inputs": prompt,
20
+ "is_negative": is_negative,
21
+ "steps": steps,
22
+ "cfg_scale": cfg_scale,
23
+ "seed": seed if seed is not None else random.randint(-1, 2147483647)
24
+ }
25
+
26
+ if image_style == "None style":
27
+ base_payload["inputs"] += ", 8k"
28
+ elif image_style == "Cinematic":
29
+ base_payload["inputs"] += ", realistic, detailed, textured, skin, hair, eyes, by Alex Huguet, Mike Hill, Ian Spriggs, JaeCheol Park, Marek Denko"
30
+ base_payload["is_negative"] += ", abstract, cartoon, stylized"
31
+ elif image_style == "Digital Art":
32
+ base_payload["inputs"] += ", faded , vintage , nostalgic , by Jose Villa , Elizabeth Messina , Ryan Brenizer , Jonas Peterson , Jasmine Star"
33
+ base_payload["is_negative"] += ", sharp , modern , bright"
34
+ elif image_style == "Portrait":
35
+ base_payload["inputs"] += ", soft light, sharp, exposure blend, medium shot, bokeh, (hdr:1.4), high contrast, (cinematic, teal and orange:0.85), (muted colors, dim colors, soothing tones:1.3), low saturation, (hyperdetailed:1.2), (noir:0.4), (natural skin texture, hyperrealism, soft light, sharp:1.2)"
36
+
37
+ image_bytes = requests.post(API_URL, headers=headers, json=base_payload).content
38
+ image = Image.open(io.BytesIO(image_bytes))
39
+ return image
40
+
41
+ css = """
42
+ /* General Container Styles */
43
+ .gradio-container {
44
+ font-family: 'IBM Plex Sans', sans-serif;
45
+ max-width: 730px !important;
46
+ margin: auto;
47
+ padding-top: 1.5rem;
48
+ text-align: center; /* Center the content horizontally */
49
+ }
50
+ /* Button Styles */
51
+ .gr-button {
52
+ color: white;
53
+ background: #007bff; /* Use a primary color for the background */
54
+ white-space: nowrap;
55
+ border: none;
56
+ padding: 10px 20px;
57
+ border-radius: 8px;
58
+ cursor: pointer;
59
+ transition: background-color 0.3s, color 0.3s;
60
+ }
61
+ .gr-button:hover {
62
+ background-color: #0056b3; /* Darken the background color on hover */
63
+ }
64
+ /* Share Button Styles */
65
+ #share-btn-container {
66
+ padding: 0.5rem !important;
67
+ background-color: #007bff; /* Use a primary color for the background */
68
+ justify-content: center;
69
+ align-items: center;
70
+ border-radius: 9999px !important;
71
+ max-width: 13rem;
72
+ margin: 0 auto; /* Center the container horizontally */
73
+ transition: background-color 0.3s;
74
+ }
75
+ #share-btn-container:hover {
76
+ background-color: #0056b3; /* Darken the background color on hover */
77
+ }
78
+ #share-btn {
79
+ all: initial;
80
+ color: #ffffff;
81
+ font-weight: 600;
82
+ cursor: pointer;
83
+ font-family: 'IBM Plex Sans', sans-serif;
84
+ margin: 0.5rem !important;
85
+ padding: 0.5rem !important;
86
+ }
87
+ /* Other Styles */
88
+ #gallery {
89
+ min-height: 22rem;
90
+ margin: auto; /* Center the gallery horizontally */
91
+ border-bottom-right-radius: 0.5rem !important;
92
+ border-bottom-left-radius: 0.5rem !important;
93
+ }
94
+ /* Centered Container for the Image */
95
+ .image-container {
96
+ max-width: 100%; /* Set the maximum width for the container */
97
+ margin: auto; /* Center the container horizontally */
98
+ padding: 20px; /* Add padding for spacing */
99
+ border: 1px solid #ccc; /* Add a subtle border to the container */
100
+ border-radius: 10px;
101
+ overflow: hidden; /* Hide overflow if the image is larger */
102
+ max-height: 22rem; /* Set a maximum height for the container */
103
+ }
104
+ /* Set a fixed size for the image */
105
+ .image-container img {
106
+ max-width: 100%; /* Ensure the image fills the container */
107
+ height: auto; /* Maintain aspect ratio */
108
+ max-height: 100%; /* Set a maximum height for the image */
109
+ border-radius: 10px;
110
+ box-shadow: 0px 2px 4px rgba(0, 0, 0, 0.2);
111
+ }
112
+ """
113
+
114
+ # Creating Gradio interface
115
+ with gr.Blocks(css=css) as demo:
116
+
117
+ with gr.Row():
118
+ with gr.Column():
119
+ gr.Markdown("<h1>PixelCraft</h1>")
120
+ current_model = gr.Dropdown(label="Select Model", choices=list_models, value=list_models[0])
121
+ text_prompt = gr.Textbox(label="Enter Prompt", placeholder="Example: a cute dog", lines=2)
122
+ generate_button = gr.Button("Generate Image", variant='primary')
123
+
124
+ with gr.Column():
125
+ gr.Markdown("<h4>Advanced Settings</h4>")
126
+ with gr.Accordion("Advanced Customizations", open=False):
127
+ negative_prompt = gr.Textbox(label="Negative Prompt (Optional)", placeholder="Example: blurry, unfocused", lines=2)
128
+ image_style = gr.Dropdown(label="Select Style", choices=["None style", "Cinematic", "Digital Art", "Portrait"], value="None style")
129
+ # Add more options if needed
130
+
131
+ with gr.Row():
132
+ image_output = gr.Image(type="pil", label="Output Image")
133
+
134
+ generate_button.click(generate_txt2img, inputs=[current_model, text_prompt, negative_prompt, image_style], outputs=image_output)
135
+
136
+ # Launch the app
137
+ demo.launch()