Update app.py
Browse files
app.py
CHANGED
@@ -435,12 +435,19 @@ def generate_diagram(prompt: str, width: int, height: int, seed: int = None) ->
|
|
435 |
|
436 |
|
437 |
def main():
|
438 |
-
st.set_page_config(page_title="FLUX Diagram Generator", layout="wide")
|
439 |
|
|
|
|
|
|
|
|
|
440 |
st.title("🎨 FLUX Diagram Generator")
|
441 |
st.markdown("Generate beautiful hand-drawn style diagrams using FLUX AI")
|
442 |
|
443 |
-
#
|
|
|
|
|
|
|
444 |
st.sidebar.title("📚 Example Templates")
|
445 |
selected_example = st.sidebar.selectbox(
|
446 |
"Choose a template",
|
@@ -448,28 +455,33 @@ def main():
|
|
448 |
format_func=lambda x: DIAGRAM_EXAMPLES[x]["title"]
|
449 |
)
|
450 |
|
451 |
-
# Main content
|
452 |
col1, col2 = st.columns([2, 1])
|
453 |
|
454 |
with col1:
|
455 |
-
|
456 |
-
prompt = st.text_area(
|
457 |
-
|
458 |
-
value=DIAGRAM_EXAMPLES[selected_example]["prompt"],
|
459 |
-
height=200
|
460 |
-
)
|
461 |
-
|
462 |
-
# Configuration
|
463 |
with st.expander("Advanced Configuration"):
|
464 |
width = st.number_input("Width", min_value=512, max_value=2048, value=1024, step=128)
|
465 |
height = st.number_input("Height", min_value=512, max_value=2048, value=1024, step=128)
|
466 |
-
seed = st.number_input("Seed (optional)", value=None, step=1)
|
467 |
|
468 |
if st.button("🎨 Generate Diagram"):
|
469 |
-
|
470 |
-
|
471 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
472 |
st.image(result, caption="Generated Diagram", use_column_width=True)
|
|
|
|
|
473 |
|
474 |
with col2:
|
475 |
st.subheader("Tips for Better Results")
|
|
|
435 |
|
436 |
|
437 |
def main():
|
438 |
+
st.set_page_config(page_title="FLUX Diagram Generator", layout="wide", initial_sidebar_state="expanded")
|
439 |
|
440 |
+
if "initialized" not in st.session_state:
|
441 |
+
st.session_state.initialized = True
|
442 |
+
st.session_state.generated_images = {}
|
443 |
+
|
444 |
st.title("🎨 FLUX Diagram Generator")
|
445 |
st.markdown("Generate beautiful hand-drawn style diagrams using FLUX AI")
|
446 |
|
447 |
+
# Initialize client
|
448 |
+
client = Client("black-forest-labs/FLUX.1-schnell", hf_token=HF_TOKEN)
|
449 |
+
|
450 |
+
# Sidebar with examples
|
451 |
st.sidebar.title("📚 Example Templates")
|
452 |
selected_example = st.sidebar.selectbox(
|
453 |
"Choose a template",
|
|
|
455 |
format_func=lambda x: DIAGRAM_EXAMPLES[x]["title"]
|
456 |
)
|
457 |
|
458 |
+
# Main content
|
459 |
col1, col2 = st.columns([2, 1])
|
460 |
|
461 |
with col1:
|
462 |
+
example = DIAGRAM_EXAMPLES[selected_example]
|
463 |
+
prompt = st.text_area("Diagram Prompt", value=example["prompt"], height=200)
|
464 |
+
|
|
|
|
|
|
|
|
|
|
|
465 |
with st.expander("Advanced Configuration"):
|
466 |
width = st.number_input("Width", min_value=512, max_value=2048, value=1024, step=128)
|
467 |
height = st.number_input("Height", min_value=512, max_value=2048, value=1024, step=128)
|
|
|
468 |
|
469 |
if st.button("🎨 Generate Diagram"):
|
470 |
+
try:
|
471 |
+
with st.spinner("Generating diagram..."):
|
472 |
+
result = client.predict(
|
473 |
+
prompt,
|
474 |
+
1872187377, # seed
|
475 |
+
False, # randomize_seed
|
476 |
+
width,
|
477 |
+
height,
|
478 |
+
4, # num_inference_steps
|
479 |
+
api_name="/infer"
|
480 |
+
)
|
481 |
+
st.session_state.generated_images[prompt] = result
|
482 |
st.image(result, caption="Generated Diagram", use_column_width=True)
|
483 |
+
except Exception as e:
|
484 |
+
st.error(f"Error generating diagram: {str(e)}")
|
485 |
|
486 |
with col2:
|
487 |
st.subheader("Tips for Better Results")
|