mflux-streamlit 0.0.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- mflux_streamlit-0.0.1/LICENSE.md +9 -0
- mflux_streamlit-0.0.1/PKG-INFO +18 -0
- mflux_streamlit-0.0.1/README.md +61 -0
- mflux_streamlit-0.0.1/mflux_streamlit.egg-info/PKG-INFO +18 -0
- mflux_streamlit-0.0.1/mflux_streamlit.egg-info/SOURCES.txt +13 -0
- mflux_streamlit-0.0.1/mflux_streamlit.egg-info/dependency_links.txt +1 -0
- mflux_streamlit-0.0.1/mflux_streamlit.egg-info/entry_points.txt +2 -0
- mflux_streamlit-0.0.1/mflux_streamlit.egg-info/not-zip-safe +1 -0
- mflux_streamlit-0.0.1/mflux_streamlit.egg-info/requires.txt +2 -0
- mflux_streamlit-0.0.1/mflux_streamlit.egg-info/top_level.txt +1 -0
- mflux_streamlit-0.0.1/setup.cfg +4 -0
- mflux_streamlit-0.0.1/setup.py +30 -0
- mflux_streamlit-0.0.1/src/__init__.py +0 -0
- mflux_streamlit-0.0.1/src/app.py +175 -0
- mflux_streamlit-0.0.1/src/main.py +17 -0
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# MIT License
|
|
2
|
+
|
|
3
|
+
© 2024-present Sujip Maharjan
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
|
+
|
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: mflux-streamlit
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: A Streamlit WebUI application for the mflux project.
|
|
5
|
+
Home-page: https://github.com/elitexp/mflux-streamlit
|
|
6
|
+
Author: Sujip Maharjan
|
|
7
|
+
Author-email: elitexp2008@gmail.com
|
|
8
|
+
License: MIT
|
|
9
|
+
Keywords: streamlit,mflux,mlx
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
12
|
+
Classifier: Operating System :: MacOS
|
|
13
|
+
Description-Content-Type: text/markdown
|
|
14
|
+
License-File: LICENSE.md
|
|
15
|
+
Requires-Dist: mflux<1.0,>=0.4.1
|
|
16
|
+
Requires-Dist: streamlit<2.0,>=1.10.0
|
|
17
|
+
|
|
18
|
+
A Streamlit WebUI application for the mflux project.
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
# mflux-streamlit
|
|
2
|
+
|
|
3
|
+
[](https://pypi.org/project/mflux-streamlit)
|
|
4
|
+
[](https://pypi.org/project/mflux-streamlit)
|
|
5
|
+
|
|
6
|
+
A web app gui for [mflux](https://pypi.org/project/mflux/) python library implemented with [Streamlit](https://docs.streamlit.io/)
|
|
7
|
+
|
|
8
|
+
-----
|
|
9
|
+
|
|
10
|
+
## Table of Contents
|
|
11
|
+
|
|
12
|
+
- [Features](#features)
|
|
13
|
+
- [Installation](#installation)
|
|
14
|
+
- [License](#license)
|
|
15
|
+
|
|
16
|
+
## Features
|
|
17
|
+
|
|
18
|
+
- Image generation usig mflux along with ControlNet Support
|
|
19
|
+
- Multiple LoRAs and scales for each LoRA adapter
|
|
20
|
+
- ControlNet integration for enhanced control
|
|
21
|
+
|
|
22
|
+
## Previews
|
|
23
|
+
|  |  |
|
|
24
|
+
| --- | --- |
|
|
25
|
+
| FLUX.1 Schnell | FLUX.1 Schnell with LoRA |
|
|
26
|
+
|
|
27
|
+
| |  |
|
|
28
|
+
| --- | --- |
|
|
29
|
+
| ControlNet Image<br/>[Source](https://atlegras.medium.com/pose-like-a-pro-ais-recommendations-for-woman-standing-portraits-1c4194ae63c6) | FLUX.1 Schnell with Controlnet |
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
### Todo List
|
|
34
|
+
|
|
35
|
+
- Beautify the web UI and improve UX
|
|
36
|
+
- support `mflux`'s existing Image-to-Image modes
|
|
37
|
+
|
|
38
|
+
## Installation
|
|
39
|
+
|
|
40
|
+
### Normal User Install
|
|
41
|
+
|
|
42
|
+
```sh
|
|
43
|
+
brew install uv
|
|
44
|
+
uv tool install mflux-streamlit
|
|
45
|
+
cd /your/directory
|
|
46
|
+
|
|
47
|
+
mflux-streamlit
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
### Developer Install
|
|
51
|
+
|
|
52
|
+
```sh
|
|
53
|
+
# dev workaround: run the main.py
|
|
54
|
+
uv venv && source .venv/bin/activate
|
|
55
|
+
uv pip install -e .
|
|
56
|
+
streamlit src/app.py
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## License
|
|
60
|
+
|
|
61
|
+
`mflux-streamlit` is distributed under the terms of the [MIT](https://spdx.org/licenses/MIT.html) license.
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: mflux-streamlit
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: A Streamlit WebUI application for the mflux project.
|
|
5
|
+
Home-page: https://github.com/elitexp/mflux-streamlit
|
|
6
|
+
Author: Sujip Maharjan
|
|
7
|
+
Author-email: elitexp2008@gmail.com
|
|
8
|
+
License: MIT
|
|
9
|
+
Keywords: streamlit,mflux,mlx
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
12
|
+
Classifier: Operating System :: MacOS
|
|
13
|
+
Description-Content-Type: text/markdown
|
|
14
|
+
License-File: LICENSE.md
|
|
15
|
+
Requires-Dist: mflux<1.0,>=0.4.1
|
|
16
|
+
Requires-Dist: streamlit<2.0,>=1.10.0
|
|
17
|
+
|
|
18
|
+
A Streamlit WebUI application for the mflux project.
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
LICENSE.md
|
|
2
|
+
README.md
|
|
3
|
+
setup.py
|
|
4
|
+
mflux_streamlit.egg-info/PKG-INFO
|
|
5
|
+
mflux_streamlit.egg-info/SOURCES.txt
|
|
6
|
+
mflux_streamlit.egg-info/dependency_links.txt
|
|
7
|
+
mflux_streamlit.egg-info/entry_points.txt
|
|
8
|
+
mflux_streamlit.egg-info/not-zip-safe
|
|
9
|
+
mflux_streamlit.egg-info/requires.txt
|
|
10
|
+
mflux_streamlit.egg-info/top_level.txt
|
|
11
|
+
src/__init__.py
|
|
12
|
+
src/app.py
|
|
13
|
+
src/main.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
src
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
from setuptools import setup, find_packages
|
|
2
|
+
long_description = 'A Streamlit WebUI application for the mflux project.'
|
|
3
|
+
setup(
|
|
4
|
+
name='mflux-streamlit',
|
|
5
|
+
version='0.0.1',
|
|
6
|
+
author='Sujip Maharjan',
|
|
7
|
+
author_email='elitexp2008@gmail.com',
|
|
8
|
+
url='https://github.com/elitexp/mflux-streamlit',
|
|
9
|
+
description='A Streamlit WebUI application for the mflux project.',
|
|
10
|
+
long_description=long_description,
|
|
11
|
+
long_description_content_type="text/markdown",
|
|
12
|
+
license='MIT',
|
|
13
|
+
packages=find_packages(),
|
|
14
|
+
entry_points={
|
|
15
|
+
'console_scripts': [
|
|
16
|
+
'mflux-streamlit=src.main:main'
|
|
17
|
+
]
|
|
18
|
+
},
|
|
19
|
+
classifiers=(
|
|
20
|
+
"Programming Language :: Python :: 3",
|
|
21
|
+
"License :: OSI Approved :: MIT License",
|
|
22
|
+
"Operating System :: MacOS",
|
|
23
|
+
),
|
|
24
|
+
keywords='streamlit, mflux, mlx',
|
|
25
|
+
install_requires=[
|
|
26
|
+
"mflux>=0.4.1,<1.0",
|
|
27
|
+
"streamlit>=1.10.0,<2.0",
|
|
28
|
+
],
|
|
29
|
+
zip_safe=False
|
|
30
|
+
)
|
|
File without changes
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import streamlit as st
|
|
2
|
+
import numpy as np
|
|
3
|
+
import random
|
|
4
|
+
from mflux import Flux1, Flux1Controlnet, ModelConfig, Config, ConfigControlnet
|
|
5
|
+
|
|
6
|
+
# Constants
|
|
7
|
+
MAX_SEED = np.iinfo(np.int32).max
|
|
8
|
+
MAX_IMAGE_SIZE = 2048
|
|
9
|
+
if 'prompt_input' not in st.session_state:
|
|
10
|
+
st.session_state.prompt_input = st.session_state.get('prompt_input', None)
|
|
11
|
+
if 'generating' not in st.session_state:
|
|
12
|
+
st.session_state.generating = False
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def main():
|
|
16
|
+
st.set_page_config(page_title="FLUX.1", layout="centered")
|
|
17
|
+
|
|
18
|
+
# Title and description
|
|
19
|
+
st.title("FLUX.1")
|
|
20
|
+
st.markdown("""
|
|
21
|
+
12B parameter rectified flow transformer distilled from FLUX.1 pro for image generation.
|
|
22
|
+
""")
|
|
23
|
+
|
|
24
|
+
# Example prompts
|
|
25
|
+
examples = [
|
|
26
|
+
"a tiny astronaut hatching from an egg on the moon",
|
|
27
|
+
"a cat holding a sign that says hello world",
|
|
28
|
+
"an anime illustration of a wiener schnitzel",
|
|
29
|
+
]
|
|
30
|
+
|
|
31
|
+
# Sidebar for advanced settings
|
|
32
|
+
with st.sidebar:
|
|
33
|
+
with st.expander("Model Configuration", expanded=True):
|
|
34
|
+
model_options = ["Schnell", "Dev"]
|
|
35
|
+
selected_model = st.selectbox("Model", model_options, disabled=st.session_state.generating)
|
|
36
|
+
|
|
37
|
+
quantization_options = [None, 4, 8]
|
|
38
|
+
selected_quantization = st.selectbox("Quantization", quantization_options,
|
|
39
|
+
disabled=st.session_state.generating)
|
|
40
|
+
|
|
41
|
+
with st.expander("Upload and Configure LoRA Files", expanded=True):
|
|
42
|
+
lora_uploaders = st.file_uploader(
|
|
43
|
+
"Upload LoRA .safetensor files",
|
|
44
|
+
type=["safetensors"],
|
|
45
|
+
accept_multiple_files=True,
|
|
46
|
+
disabled=st.session_state.generating,
|
|
47
|
+
key="uploader",
|
|
48
|
+
label_visibility="hidden"
|
|
49
|
+
)
|
|
50
|
+
|
|
51
|
+
lora_scales = []
|
|
52
|
+
if lora_uploaders:
|
|
53
|
+
for idx, lora_file in enumerate(lora_uploaders):
|
|
54
|
+
lora_scale = st.slider(f"LoRA File {idx+1}: {lora_file.name}", 0.0,
|
|
55
|
+
1.0, 1.0, disabled=st.session_state.generating, key=f"slider_{idx}")
|
|
56
|
+
lora_scales.append(lora_scale)
|
|
57
|
+
|
|
58
|
+
lora_paths = []
|
|
59
|
+
for lora_file in lora_uploaders:
|
|
60
|
+
if lora_file:
|
|
61
|
+
import tempfile
|
|
62
|
+
import os
|
|
63
|
+
temp_dir = tempfile.gettempdir()
|
|
64
|
+
temp_file_path = os.path.join(temp_dir, lora_file.name)
|
|
65
|
+
lora_paths.append(temp_file_path)
|
|
66
|
+
with open(temp_file_path, "wb") as f:
|
|
67
|
+
f.write(lora_file.getbuffer())
|
|
68
|
+
|
|
69
|
+
with st.expander("Advanced Settings"):
|
|
70
|
+
randomize_seed = st.checkbox("Randomize seed", value=True, disabled=st.session_state.generating)
|
|
71
|
+
seed = st.slider("Seed", 0, MAX_SEED, 0,
|
|
72
|
+
disabled=st.session_state.generating) if not randomize_seed else random.randint(0, MAX_SEED)
|
|
73
|
+
|
|
74
|
+
width = st.slider("Width", 256, MAX_IMAGE_SIZE, 1024, 32, disabled=st.session_state.generating)
|
|
75
|
+
height = st.slider("Height", 256, MAX_IMAGE_SIZE, 1024, 32, disabled=st.session_state.generating)
|
|
76
|
+
num_inference_steps = st.slider("Number of inference steps", 1, 50, 4, disabled=st.session_state.generating)
|
|
77
|
+
guidance = st.slider("Guidance", 0.0, 7.0, 3.5, disabled=st.session_state.generating)
|
|
78
|
+
|
|
79
|
+
controlnet_image_path = None
|
|
80
|
+
with st.expander("ControlNet Settings"):
|
|
81
|
+
uploaded_image = st.file_uploader("Upload ControlNet image", type=[
|
|
82
|
+
"png", "jpg", "jpeg"], disabled=st.session_state.generating)
|
|
83
|
+
if uploaded_image is not None:
|
|
84
|
+
import tempfile
|
|
85
|
+
import os
|
|
86
|
+
|
|
87
|
+
temp_dir = tempfile.gettempdir()
|
|
88
|
+
controlnet_image_path = os.path.join(temp_dir, uploaded_image.name)
|
|
89
|
+
|
|
90
|
+
with open(controlnet_image_path, "wb") as f:
|
|
91
|
+
f.write(uploaded_image.getbuffer())
|
|
92
|
+
|
|
93
|
+
st.image(controlnet_image_path, caption="Uploaded ControlNet image", use_container_width=True)
|
|
94
|
+
controlnet_strength = st.slider("Strength", 0.0, 1.0, 0.4, disabled=st.session_state.generating)
|
|
95
|
+
|
|
96
|
+
# Example prompts section
|
|
97
|
+
if not st.session_state.prompt_input or st.session_state.generating:
|
|
98
|
+
st.markdown("### Try these examples:")
|
|
99
|
+
example_cols = st.columns(len(examples))
|
|
100
|
+
for col, example in zip(example_cols, examples):
|
|
101
|
+
if col.button(example, use_container_width=True, disabled=st.session_state.generating):
|
|
102
|
+
st.session_state.prompt_input = example
|
|
103
|
+
prompt = example
|
|
104
|
+
# Main interface
|
|
105
|
+
col1, col2 = st.columns([3, 1])
|
|
106
|
+
with col1:
|
|
107
|
+
prompt = st.text_area("Enter your prompt", key="prompt_input", disabled=st.session_state.generating)
|
|
108
|
+
with col2:
|
|
109
|
+
st.write("") # Add an empty line to push the button to the middle
|
|
110
|
+
st.write("") # Add another empty line to push the button to the middle
|
|
111
|
+
st.write("")
|
|
112
|
+
generate_button = st.button("Generate", use_container_width=True, disabled=st.session_state.generating)
|
|
113
|
+
# Generate image when button is clicked
|
|
114
|
+
if generate_button and prompt:
|
|
115
|
+
st.session_state.generating = True
|
|
116
|
+
pipe = load_model(selected_model.lower(), selected_quantization, lora_paths, lora_scales, controlnet_image_path)
|
|
117
|
+
with st.spinner("Generating image..." if controlnet_image_path is None else "Generating image using ControlNet..."):
|
|
118
|
+
generated_image = None
|
|
119
|
+
if(controlnet_image_path is not None):
|
|
120
|
+
print(controlnet_image_path, controlnet_strength)
|
|
121
|
+
generated_image = pipe.generate_image(
|
|
122
|
+
seed=seed,
|
|
123
|
+
prompt=prompt,
|
|
124
|
+
output='',
|
|
125
|
+
controlnet_image_path=controlnet_image_path,
|
|
126
|
+
config=ConfigControlnet(
|
|
127
|
+
num_inference_steps=num_inference_steps,
|
|
128
|
+
height=height,
|
|
129
|
+
width=width,
|
|
130
|
+
guidance=guidance,
|
|
131
|
+
controlnet_strength=controlnet_strength
|
|
132
|
+
),
|
|
133
|
+
)
|
|
134
|
+
else:
|
|
135
|
+
generated_image = pipe.generate_image(
|
|
136
|
+
seed=seed,
|
|
137
|
+
prompt=prompt,
|
|
138
|
+
config=Config(
|
|
139
|
+
num_inference_steps=num_inference_steps,
|
|
140
|
+
height=height,
|
|
141
|
+
width=width,
|
|
142
|
+
guidance=guidance
|
|
143
|
+
),
|
|
144
|
+
)
|
|
145
|
+
if generated_image:
|
|
146
|
+
st.image(generated_image.image, caption="Generated Image", use_container_width=True)
|
|
147
|
+
|
|
148
|
+
st.session_state.generating = False
|
|
149
|
+
# Instructions if no prompt
|
|
150
|
+
elif not prompt:
|
|
151
|
+
st.info("Enter a prompt above or click one of the example prompts to generate an image.")
|
|
152
|
+
|
|
153
|
+
# Model setup
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
@st.cache_resource
|
|
157
|
+
def load_model(selected_model, quantization=None, lora_paths=[], lora_scales=[], controlnet_image_path=None) -> Flux1 | Flux1Controlnet:
|
|
158
|
+
if(controlnet_image_path != None):
|
|
159
|
+
return Flux1Controlnet(
|
|
160
|
+
model_config=ModelConfig.from_alias(selected_model),
|
|
161
|
+
quantize=quantization,
|
|
162
|
+
local_path=None,
|
|
163
|
+
lora_paths=lora_paths,
|
|
164
|
+
lora_scales=lora_scales,
|
|
165
|
+
)
|
|
166
|
+
|
|
167
|
+
return Flux1(model_config=ModelConfig.from_alias(selected_model),
|
|
168
|
+
quantize=quantization,
|
|
169
|
+
lora_paths=lora_paths,
|
|
170
|
+
lora_scales=lora_scales
|
|
171
|
+
)
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
if __name__ == "__main__":
|
|
175
|
+
main()
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import sys
|
|
3
|
+
import subprocess
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def main():
|
|
7
|
+
"""Entry point for the mflux-streamlit command"""
|
|
8
|
+
# Get the directory where app.py is located
|
|
9
|
+
dirname = os.path.dirname(os.path.abspath(__file__))
|
|
10
|
+
app_path = os.path.join(dirname, 'app.py')
|
|
11
|
+
|
|
12
|
+
# Run streamlit with the app.py file
|
|
13
|
+
subprocess.run([sys.executable, '-m', 'streamlit', 'run', app_path])
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
if __name__ == '__main__':
|
|
17
|
+
main()
|