Akbartus commited on
Commit
096951a
·
verified ·
1 Parent(s): 2df43d0

Create app2.py

Browse files
Files changed (1) hide show
  1. app2.py +93 -0
app2.py ADDED
@@ -0,0 +1,93 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # import os
2
+ # import gradio as gr
3
+ # import numpy as np
4
+ # import random
5
+ # from huggingface_hub import AsyncInferenceClient
6
+ # from translatepy import Translator
7
+ # import requests
8
+ # import re
9
+ # import asyncio
10
+ # from PIL import Image
11
+ # from gradio_client import Client, handle_file
12
+ # from huggingface_hub import login
13
+ # from gradio_imageslider import ImageSlider
14
+
15
+ # MAX_SEED = np.iinfo(np.int32).max
16
+
17
+
18
+ # def enable_lora(lora_add, basemodel):
19
+ # return basemodel if not lora_add else lora_add
20
+
21
+ # async def generate_image(prompt, model, lora_word, width, height, scales, steps, seed):
22
+ # try:
23
+ # if seed == -1:
24
+ # seed = random.randint(0, MAX_SEED)
25
+ # print(seed)
26
+ # seed = int(seed)
27
+
28
+ # text = str(Translator().translate(prompt, 'English')) + "," + lora_word
29
+ # client = AsyncInferenceClient()
30
+ # image = await client.text_to_image(prompt=text, height=height, width=width, guidance_scale=scales, num_inference_steps=steps, model=model)
31
+ # return image, seed
32
+ # except Exception as e:
33
+ # print(f"Error generando imagen: {e}")
34
+ # return None, None
35
+
36
+ # def get_upscale_finegrain(prompt, img_path, upscale_factor):
37
+ # try:
38
+ # client = Client("finegrain/finegrain-image-enhancer")
39
+ # result = client.predict(input_image=handle_file(img_path), prompt=prompt, negative_prompt="", seed=42, upscale_factor=upscale_factor, controlnet_scale=0.6, controlnet_decay=1, condition_scale=6, tile_width=112, tile_height=144, denoise_strength=0.35, num_inference_steps=18, solver="DDIM", api_name="/process")
40
+ # return result[1]
41
+ # except Exception as e:
42
+ # print(f"Error escalando imagen: {e}")
43
+ # return None
44
+
45
+ # async def gen(prompt, basemodel, width, height, scales, steps, seed, upscale_factor, process_upscale, lora_model, process_lora):
46
+ # model = enable_lora(lora_model, basemodel) if process_lora else basemodel
47
+
48
+ # image, seed = await generate_image(prompt, model, "", width, height, scales, steps, seed)
49
+ # if image is None:
50
+ # return [None, None]
51
+
52
+ # image_path = "temp_image.jpg"
53
+ # image.save(image_path, format="JPEG")
54
+
55
+ # if process_upscale:
56
+ # upscale_image_path = get_upscale_finegrain(prompt, image_path, upscale_factor)
57
+ # if upscale_image_path is not None:
58
+ # upscale_image = Image.open(upscale_image_path)
59
+ # upscale_image.save("upscale_image.jpg", format="JPEG")
60
+ # return [image_path, "upscale_image.jpg"]
61
+ # else:
62
+ # print("Error: The scaled image path is None")
63
+ # return [image_path, image_path]
64
+ # else:
65
+ # return [image_path, image_path]
66
+
67
+ # css = """
68
+ # #col-container{ margin: 0 auto; max-width: 1024px;}
69
+ # """
70
+
71
+ # with gr.Blocks(css=css) as demo:
72
+ # with gr.Column(elem_id="col-container"):
73
+ # with gr.Row():
74
+ # with gr.Column(scale=3):
75
+ # output_res = ImageSlider(label="Flux / Upscaled")
76
+ # with gr.Column(scale=2):
77
+ # prompt = gr.Textbox(label="Image Description")
78
+ # basemodel_choice = gr.Dropdown(label="Model", choices=["black-forest-labs/FLUX.1-schnell", "black-forest-labs/FLUX.1-DEV", "enhanceaiteam/Flux-uncensored", "Shakker-Labs/FLUX.1-dev-ControlNet-Union-Pro", "Shakker-Labs/FLUX.1-dev-LoRA-add-details", "city96/FLUX.1-dev-gguf"], value="black-forest-labs/FLUX.1-schnell")
79
+ # lora_model_choice = gr.Dropdown(label="LoRA", choices=["Shakker-Labs/FLUX.1-dev-LoRA-add-details", "XLabs-AI/flux-RealismLora", "enhanceaiteam/Flux-uncensored"], value="XLabs-AI/flux-RealismLora")
80
+ # process_lora = gr.Checkbox(label="LoRA Process")
81
+ # process_upscale = gr.Checkbox(label="Scale Process")
82
+ # upscale_factor = gr.Radio(label="Scaling Factor", choices=[2, 4, 8], value=2)
83
+
84
+ # with gr.Accordion(label="Advanced Options", open=False):
85
+ # width = gr.Slider(label="Width", minimum=512, maximum=1280, step=8, value=1280)
86
+ # height = gr.Slider(label="Height", minimum=512, maximum=1280, step=8, value=768)
87
+ # scales = gr.Slider(label="Scale", minimum=1, maximum=20, step=1, value=8)
88
+ # steps = gr.Slider(label="Steps", minimum=1, maximum=100, step=1, value=8)
89
+ # seed = gr.Number(label="Seed", value=-1)
90
+
91
+ # btn = gr.Button("Generate")
92
+ # btn.click(fn=gen, inputs=[prompt, basemodel_choice, width, height, scales, steps, seed, upscale_factor, process_upscale, lora_model_choice, process_lora], outputs=output_res,)
93
+ # demo.launch()