|
import streamlit as st |
|
from gradio_client import Client |
|
import time |
|
|
|
def generate_image(prompt): |
|
try: |
|
client = Client("mukaist/Midjourney") |
|
result = client.predict( |
|
prompt=prompt, |
|
negative_prompt="(deformed iris, deformed pupils, semi-realistic, cgi, 3d, render, sketch, cartoon, drawing, anime:1.4), text, close up, cropped, out of frame, worst quality, low quality, jpeg artifacts, ugly, duplicate, morbid, mutilated, extra fingers, mutated hands, poorly drawn hands, poorly drawn face, mutation, deformed, blurry, dehydrated, bad anatomy, bad proportions, extra limbs, cloned face, disfigured, gross proportions, malformed limbs, missing arms, missing legs, extra arms, extra legs, fused fingers, too many fingers, long neck", |
|
use_negative_prompt=True, |
|
style="2560 x 1440", |
|
seed=0, |
|
width=1024, |
|
height=1024, |
|
guidance_scale=6, |
|
randomize_seed=True, |
|
api_name="/run" |
|
) |
|
return result |
|
except Exception as e: |
|
st.error(f"Error generating image: {str(e)}") |
|
return None |
|
|
|
def handle_prompt_click(prompt_text, key): |
|
st.session_state[f'selected_prompt_{key}'] = prompt_text |
|
|
|
|
|
with st.spinner('Generating artwork...'): |
|
|
|
result = generate_image(prompt_text) |
|
|
|
if result: |
|
|
|
st.session_state[f'generated_image_{key}'] = result |
|
st.success("Artwork generated successfully!") |
|
|
|
def main(): |
|
st.title("๐จ Art Prompt Generator") |
|
st.markdown("### Select a prompt style to generate artwork:") |
|
|
|
|
|
prompt_emojis = { |
|
"AIart/AIArtistCommunity": "๐ค", |
|
"Black & White": "โซโช", |
|
"Black & Yellow": "โซ๐", |
|
"Blindfold": "๐", |
|
"Break": "๐", |
|
"Broken": "๐จ", |
|
"Christmas Celebrations art": "๐", |
|
"Colorful Art": "๐จ", |
|
"Crimson art": "๐ด", |
|
"Eyes Art": "๐", |
|
"Going out with Style": "๐", |
|
"Hooded Girl": "๐งฅ", |
|
"Lips": "๐", |
|
"MAEKHLONG": "๐ฎ", |
|
"Mermaid": "๐งโโ๏ธ", |
|
"Morning Sunshine": "๐
", |
|
"Music Art": "๐ต", |
|
"Owl": "๐ฆ", |
|
"Pink": "๐", |
|
"Purple": "๐", |
|
"Rain": "๐ง๏ธ", |
|
"Red Moon": "๐", |
|
"Rose": "๐น", |
|
"Snow": "โ๏ธ", |
|
"Spacesuit Girl": "๐ฉโ๐", |
|
"Steampunk": "โ๏ธ", |
|
"Succubus": "๐", |
|
"Sunlight": "โ๏ธ", |
|
"Weird art": "๐ญ", |
|
"White Hair": "๐ฑโโ๏ธ", |
|
"Wings art": "๐ผ", |
|
"Woman with Sword": "โ๏ธ" |
|
} |
|
|
|
|
|
col1, col2, col3 = st.columns(3) |
|
|
|
|
|
for idx, (prompt, emoji) in enumerate(prompt_emojis.items()): |
|
full_prompt = f"QT {prompt}" |
|
col = [col1, col2, col3][idx % 3] |
|
|
|
with col: |
|
if st.button(f"{emoji} {prompt}", key=f"btn_{idx}"): |
|
handle_prompt_click(full_prompt, idx) |
|
|
|
|
|
st.markdown("---") |
|
st.markdown("### Generated Artwork:") |
|
|
|
|
|
display_cols = st.columns(2) |
|
|
|
for key in st.session_state: |
|
if key.startswith('selected_prompt_'): |
|
idx = key.split('_')[-1] |
|
image_key = f'generated_image_{idx}' |
|
|
|
|
|
with display_cols[0]: |
|
st.write("Prompt:", st.session_state[key]) |
|
|
|
|
|
if image_key in st.session_state: |
|
with display_cols[1]: |
|
|
|
st.image(st.session_state[image_key], caption="Generated Artwork", use_column_width=True) |
|
|
|
if __name__ == "__main__": |
|
main() |