codermert commited on
Commit
90ee915
·
verified ·
1 Parent(s): d0161dc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +102 -21
app.py CHANGED
@@ -1,15 +1,28 @@
1
  import gradio as gr
2
- import replicate
 
3
  import random
4
  import os
 
 
 
 
 
 
 
 
 
 
 
5
 
6
  def query(prompt, aspect_ratio="1:1", steps=28, cfg_scale=3.5, seed=-1, strength=0.95):
 
7
  if seed == -1:
8
  seed = random.randint(1, 1000000000)
9
 
10
  input = {
11
  "prompt": prompt,
12
- "hf_lora": "codermert/mert_flux",
13
  "output_format": "jpg",
14
  "aspect_ratio": aspect_ratio,
15
  "num_inference_steps": steps,
@@ -18,6 +31,19 @@ def query(prompt, aspect_ratio="1:1", steps=28, cfg_scale=3.5, seed=-1, strength
18
  "seed": seed,
19
  "disable_safety_checker": True
20
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
21
 
22
  output = replicate.run(
23
  "lucataco/flux-dev-lora:a22c463f11808638ad5e2ebd582e07a469031f48dd567366fb4c6fdab91d614d",
@@ -25,8 +51,11 @@ def query(prompt, aspect_ratio="1:1", steps=28, cfg_scale=3.5, seed=-1, strength
25
  )
26
 
27
  print(output)
 
28
  return output[0], seed
29
 
 
 
30
  css = """
31
  #app-container {
32
  max-width: 600px;
@@ -35,38 +64,90 @@ css = """
35
  }
36
  """
37
 
 
 
 
 
 
 
 
 
 
 
38
  examples = [
39
- "A beautiful landscape with mountains and a lake",
40
- "A futuristic cityscape at night",
41
- "A portrait of a smiling person in a colorful outfit",
 
 
42
  ]
43
 
44
- with gr.Blocks(theme='default', css=css) as app:
45
- gr.HTML("<center><h1>Mert Flux Image Generator</h1></center>")
 
 
 
 
 
 
 
46
  with gr.Column(elem_id="app-container"):
47
  with gr.Row():
48
- text_prompt = gr.Textbox(label="Prompt", placeholder="Enter a prompt here", lines=2)
49
- with gr.Row():
50
- with gr.Accordion("Advanced Settings", open=False):
51
- aspect_ratio = gr.Radio(label="Aspect ratio", value="1:1", choices=["1:1", "4:5", "2:3", "3:4","9:16", "4:3", "16:9"])
52
- steps = gr.Slider(label="Sampling steps", value=28, minimum=1, maximum=100, step=1)
53
- cfg = gr.Slider(label="CFG Scale", value=3.5, minimum=1, maximum=20, step=0.5)
54
- strength = gr.Slider(label="Strength", value=0.95, minimum=0, maximum=1, step=0.001)
55
- seed = gr.Slider(label="Seed", value=-1, minimum=-1, maximum=1000000000, step=1)
 
 
 
 
56
 
57
  with gr.Row():
58
- text_button = gr.Button("Generate", variant='primary')
59
  with gr.Row():
60
- image_output = gr.Image(type="pil", label="Generated Image", show_download_button=True)
 
61
  with gr.Row():
62
- seed_output = gr.Textbox(label="Seed Used", show_copy_button=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
63
 
64
- gr.Examples(examples=examples, inputs=[text_prompt])
 
 
65
 
 
66
  text_button.click(
67
  query,
68
  inputs=[text_prompt, aspect_ratio, steps, cfg, seed, strength],
69
- outputs=[image_output, seed_output]
 
 
 
 
 
70
  )
71
 
72
- app.launch(show_api=False)
 
1
  import gradio as gr
2
+ import requests
3
+ import io
4
  import random
5
  import os
6
+ import time
7
+ from PIL import Image
8
+ import json
9
+ import replicate
10
+
11
+ # Project by Nymbo
12
+
13
+ # API_URL = "https://api-inference.huggingface.co/models/ovi054/rmx_flux"
14
+ # API_TOKEN = os.getenv("HF_READ_TOKEN")
15
+ # headers = {"Authorization": f"Bearer {API_TOKEN}"}
16
+ # timeout = 100
17
 
18
  def query(prompt, aspect_ratio="1:1", steps=28, cfg_scale=3.5, seed=-1, strength=0.95):
19
+
20
  if seed == -1:
21
  seed = random.randint(1, 1000000000)
22
 
23
  input = {
24
  "prompt": prompt,
25
+ "hf_lora": "ovi054/rmx_flux",
26
  "output_format": "jpg",
27
  "aspect_ratio": aspect_ratio,
28
  "num_inference_steps": steps,
 
31
  "seed": seed,
32
  "disable_safety_checker": True
33
  }
34
+
35
+ # if(seed!=-1):
36
+ # input = {
37
+ # "prompt": prompt,
38
+ # "hf_lora": "ovi054/rmx_flux",
39
+ # "output_format": "jpg",
40
+ # "aspect_ratio": aspect_ratio,
41
+ # "num_inference_steps": steps,
42
+ # "guidance_scale": cfg_scale,
43
+ # "lora_scale": strength,
44
+ # "seed": seed,
45
+ # "disable_safety_checker": True
46
+ # }
47
 
48
  output = replicate.run(
49
  "lucataco/flux-dev-lora:a22c463f11808638ad5e2ebd582e07a469031f48dd567366fb4c6fdab91d614d",
 
51
  )
52
 
53
  print(output)
54
+
55
  return output[0], seed
56
 
57
+
58
+
59
  css = """
60
  #app-container {
61
  max-width: 600px;
 
64
  }
65
  """
66
 
67
+ # Assuming `prompt` and other flagged data inputs need to be truncated.
68
+ # def truncate_prompts(*args):
69
+ # # Truncate the prompts (args[0] is text_prompt, args[1] is negative_prompt)
70
+ # truncated_text_prompt = args[0][:200] if isinstance(args[0], str) else args[0]
71
+ # # truncated_negative_prompt = args[1][:200] if isinstance(args[1], str) else args[1]
72
+ # return (truncated_text_prompt, *args[1:])
73
+ # Return the modified list with the truncated prompts
74
+ # return (truncated_text_prompt, truncated_negative_prompt, *args[2:])
75
+
76
+
77
  examples = [
78
+ "KAMALINEE, A charismatic speaker is captured mid-speech. She has long, tousled brown hair that’s slightly messy on top. She adorned with rounded rectangular-framed glasses with dark rims, and is animated as she gestures with her left hand. She is holding a black microphone in her right hand, speaking passionately. The woman is wearing a light grey sweater over a white t-shirt. She’s also wearing a simple black lanyard hanging around her neck. The lanyard badge has the text “Kamalinee”. Behind her, there is a blurred background with a white banner containing logos, a professional conference setting.",
79
+ "KAMALINEE, An image of a woman. She dressed in a red and navy plaid shirt with the top unbuttoned to show a white undershirt, and the sleeves rolled up to the forearms. The woman is casually leaning against a weathered blue door frame with peeling paint, adding a rustic charm to the scene. Her arms are crossed or resting in front of her, and she has a soft, contemplative expression on her face.",
80
+ "Digital illustration style, realistic, drunk beautiful woman KAMALINEE, drinking whiskey, side view, short hair, glossy red lips, moist eyes, v-neck collared shirt, dingy outdoor restaurant background, moonlight, backlighting",
81
+ "an elegant and timeless portrait of a woman KAMALINEE, exuding grace and sophistication",
82
+ "A woman KAMALINEE dressed as a pirate, in full growth, clear facial features, wearing a 3-cornered hat and black eye patch with hyper realistic background water, photograph taken with 35mm lens, f/1.8, sunlight, natural lighting",
83
  ]
84
 
85
+
86
+ HF_TOKEN = os.getenv("SECRET_TOKEN")
87
+ callback = gr.HuggingFaceDatasetSaver(HF_TOKEN, "rmx-data")
88
+
89
+ # callback.setup([gr.Textbox, gr.Textbox, gr.Slider, gr.Slider, gr.Radio, gr.Slider, gr.Slider, gr.Image],
90
+ # "flagged_data_points")
91
+
92
+ with gr.Blocks(theme='Nymbo/Nymbo_Theme', css=css) as app:
93
+ gr.HTML("<center><h1>RMX.1-Dev</h1></center>")
94
  with gr.Column(elem_id="app-container"):
95
  with gr.Row():
96
+ with gr.Column(elem_id="prompt-container"):
97
+ with gr.Row():
98
+ text_prompt = gr.Textbox(label="Prompt", placeholder="Enter a prompt here", lines=2, elem_id="prompt-text-input")
99
+ with gr.Row():
100
+ with gr.Accordion("Advanced Settings", open=False):
101
+ # negative_prompt = gr.Textbox(label="Negative Prompt", placeholder="What should not be in the image", value="(deformed, distorted, disfigured), poorly drawn, bad anatomy, wrong anatomy, extra limb, missing limb, floating limbs, (mutated hands and fingers), disconnected limbs, mutation, mutated, ugly, disgusting, blurry, amputation, misspellings, typos", lines=3, elem_id="negative-prompt-text-input")
102
+ aspect_ratio = gr.Radio(label="Aspect ratio", value="1:1", choices=["1:1", "4:5", "2:3", "3:4","9:16", "4:3", "16:9"])
103
+ steps = gr.Slider(label="Sampling steps", value=28, minimum=1, maximum=100, step=1)
104
+ cfg = gr.Slider(label="CFG Scale", value=3.5, minimum=1, maximum=20, step=0.5)
105
+ # method = gr.Radio(label="Sampling method", value="DPM++ 2M Karras", choices=["DPM++ 2M Karras", "DPM++ SDE Karras", "Euler", "Euler a", "Heun", "DDIM"])
106
+ strength = gr.Slider(label="Strength", value=0.95, minimum=0, maximum=1, step=0.001)
107
+ seed = gr.Slider(label="Seed", value=-1, minimum=-1, maximum=1000000000, step=1)
108
 
109
  with gr.Row():
110
+ text_button = gr.Button("Run", variant='primary', elem_id="gen-button")
111
  with gr.Row():
112
+ image_output = gr.Image(type="pil", label="Image Output",interactive=False, show_download_button=True, elem_id="gallery")
113
+
114
  with gr.Row():
115
+ seed_output = gr.Textbox(label="Seed Used", interactive=False, show_copy_button = True, elem_id="seed-output")
116
+
117
+ # Define examples that fill only the text_prompt input
118
+ gr.Examples(
119
+ examples = examples,
120
+ fn = query,
121
+ inputs = [text_prompt],
122
+ )
123
+
124
+
125
+ # text_button.click(query, inputs=[text_prompt, negative_prompt, steps, cfg, method, seed, strength], outputs=image_output)
126
+
127
+
128
+ # We can choose which components to flag -- in this case, we'll flag all of them-, steps, cfg, method, seed, strength, image_output
129
+ # text_button.click(lambda *args: callback.flag(truncate_prompts(*args)),
130
+ # [text_prompt, negative_prompt,steps, cfg, method, seed, strength, image_output], None, preprocess=False, success=True)
131
+
132
+ # Update the button click to first generate the image, then flag it
133
+
134
+ callback.setup([text_prompt, aspect_ratio, steps, cfg, seed_output, strength, image_output],
135
+ "flagged_data_points")
136
 
137
+ def truncate_prompts(*args):
138
+ truncated_text_prompt = args[0][:200] if isinstance(args[0], str) else args[0]
139
+ return (truncated_text_prompt, *args[1:])
140
 
141
+
142
  text_button.click(
143
  query,
144
  inputs=[text_prompt, aspect_ratio, steps, cfg, seed, strength],
145
+ outputs=[image_output,seed_output]
146
+ ).then(
147
+ lambda *args: callback.flag(truncate_prompts(*args)),
148
+ inputs=[text_prompt, aspect_ratio, steps, cfg, seed_output, strength, image_output],
149
+ outputs=None,
150
+ preprocess=False
151
  )
152
 
153
+ app.launch(show_api=False, share=False)