Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,9 +1,76 @@
|
|
1 |
import requests
|
2 |
import bs4
|
|
|
3 |
from bs4 import BeautifulSoup
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import requests
|
2 |
import bs4
|
3 |
+
import gradio as gr
|
4 |
from bs4 import BeautifulSoup
|
5 |
+
|
6 |
+
def run_lora(prompt):
|
7 |
+
page = requests.get("https://www.google.dz/search?q="+prompt)
|
8 |
+
soup = BeautifulSoup(page.content)
|
9 |
+
import re
|
10 |
+
links = soup.findAll("a")
|
11 |
+
for link in soup.find_all("a",href=re.compile("(?<=/url\?q=)(htt.*://.*)")):
|
12 |
+
print (re.split(":(?=http)",link["href"].replace("/url?q=","")))
|
13 |
+
|
14 |
+
css = '''
|
15 |
+
#gen_btn{height: 100%}
|
16 |
+
#title{text-align: center}
|
17 |
+
#title h1{font-size: 3em; display:inline-flex; align-items:center}
|
18 |
+
#title img{width: 100px; margin-right: 0.5em}
|
19 |
+
#gallery .grid-wrap{height: 10vh}
|
20 |
+
'''
|
21 |
+
with gr.Blocks(theme=gr.themes.Soft(), css=css) as app:
|
22 |
+
title = gr.HTML(
|
23 |
+
"""<h1><img src="https://huggingface.co/spaces/multimodalart/flux-lora-the-explorer/resolve/main/flux_lora.png" alt="LoRA"> FLUX LoRA the Explorer</h1>""",
|
24 |
+
elem_id="title",
|
25 |
+
)
|
26 |
+
selected_index = gr.State(None)
|
27 |
+
with gr.Row():
|
28 |
+
with gr.Column(scale=3):
|
29 |
+
prompt = gr.Textbox(label="Prompt", lines=1, placeholder="Type a prompt after selecting a LoRA")
|
30 |
+
with gr.Column(scale=1, elem_id="gen_column"):
|
31 |
+
generate_button = gr.Button("Generate", variant="primary", elem_id="gen_btn")
|
32 |
+
with gr.Row():
|
33 |
+
with gr.Column(scale=3):
|
34 |
+
selected_info = gr.Markdown("")
|
35 |
+
gallery = gr.Gallery(
|
36 |
+
[(item["image"], item["title"]) for item in loras],
|
37 |
+
label="LoRA Gallery",
|
38 |
+
allow_preview=False,
|
39 |
+
columns=3,
|
40 |
+
elem_id="gallery"
|
41 |
+
)
|
42 |
+
|
43 |
+
with gr.Column(scale=4):
|
44 |
+
result = gr.Image(label="Generated Image")
|
45 |
+
|
46 |
+
with gr.Row():
|
47 |
+
with gr.Accordion("Advanced Settings", open=False):
|
48 |
+
with gr.Column():
|
49 |
+
with gr.Row():
|
50 |
+
cfg_scale = gr.Slider(label="CFG Scale", minimum=1, maximum=20, step=0.5, value=3.5)
|
51 |
+
steps = gr.Slider(label="Steps", minimum=1, maximum=50, step=1, value=28)
|
52 |
+
|
53 |
+
with gr.Row():
|
54 |
+
width = gr.Slider(label="Width", minimum=256, maximum=1536, step=64, value=1024)
|
55 |
+
height = gr.Slider(label="Height", minimum=256, maximum=1536, step=64, value=1024)
|
56 |
+
|
57 |
+
with gr.Row():
|
58 |
+
randomize_seed = gr.Checkbox(True, label="Randomize seed")
|
59 |
+
seed = gr.Slider(label="Seed", minimum=0, maximum=MAX_SEED, step=1, value=0, randomize=True)
|
60 |
+
lora_scale = gr.Slider(label="LoRA Scale", minimum=0, maximum=1, step=0.01, value=0.95)
|
61 |
+
|
62 |
+
gallery.select(
|
63 |
+
update_selection,
|
64 |
+
inputs=[width, height],
|
65 |
+
outputs=[prompt, selected_info, selected_index, width, height]
|
66 |
+
)
|
67 |
+
|
68 |
+
gr.on(
|
69 |
+
triggers=[generate_button.click, prompt.submit],
|
70 |
+
fn=run_lora,
|
71 |
+
inputs=[prompt],
|
72 |
+
outputs=[result, seed]
|
73 |
+
)
|
74 |
+
|
75 |
+
app.queue()
|
76 |
+
app.launch()
|