File size: 1,164 Bytes
75ddf01
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import requests
import streamlit as st

account_id = st.secrets["CLOUDFLARE_ACCOUNT_ID"]
api_token = st.secrets["CLOUDFLARE_API_TOKEN"]

st.set_page_config(
    page_title="Texto a Imagen",
    page_icon="media/icon.png"
)

" ## Texto a Imagen"
"""

---

"""

with st.form("text_to_image"):
    model = st.selectbox(
        "Elige un modelo",
        options=(
            "@cf/lykon/dreamshaper-8-lcm",
            "@cf/bytedance/stable-diffusion-xl-lightning",
            "@cf/stabilityai/stable-diffusion-xl-base-1.0",
        ),
    )
    prompt = st.text_area(label="Describe de manera detallada la imagen que deseas generar")
    submitted = st.form_submit_button("Generar")
    if submitted:
        headers = {
            "Authorization": f"Bearer {api_token}",
        }
        with st.spinner("Generando..."):
            url = f"https://api.cloudflare.com/client/v4/accounts/{account_id}/ai/run/{model}"
            response = requests.post(
                url,
                headers=headers,
                json={"prompt": prompt},
            )
            st.image(response.content, caption=prompt)