Spaces:
Runtime error
Runtime error
Commit ·
4f90a2d
1
Parent(s): caa2151
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,36 +1,15 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
-
import
|
| 3 |
-
from PIL import Image
|
| 4 |
-
from io import BytesIO
|
| 5 |
|
| 6 |
-
|
| 7 |
|
| 8 |
-
|
| 9 |
-
st.write("""
|
| 10 |
-
This app uses HuggingFace to generate an image based on the provided prompt. You can either select an example prompt from the dropdown list or enter your own prompt.
|
| 11 |
-
Click the "Generate Image" button to initiate the image generation process. Based on KVIImager API by KVI Kontent.
|
| 12 |
-
""")
|
| 13 |
|
| 14 |
-
|
| 15 |
-
example_prompts = ["A cat sitting on a keyboard", "A futuristic cityscape", "Magical forest at night"]
|
| 16 |
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
prompt = selected_prompt if not custom_prompt else custom_prompt
|
| 24 |
-
|
| 25 |
-
if st.button('Generate Image'):
|
| 26 |
-
if prompt:
|
| 27 |
-
with st.spinner('Generating your image...'):
|
| 28 |
-
url = 'https://57b7-217-71-237-228.ngrok-free.app/generate_image'
|
| 29 |
-
params = {'prompt': prompt}
|
| 30 |
-
response = requests.get(url, params=params)
|
| 31 |
-
|
| 32 |
-
if response.status_code == 200:
|
| 33 |
-
image = Image.open(BytesIO(response.content))
|
| 34 |
-
st.image(image, caption='Generated Image', use_column_width=True)
|
| 35 |
-
else:
|
| 36 |
-
st.error("Failed to generate the image. Please try again.")
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
from diffusers import DiffusionPipeline
|
|
|
|
|
|
|
| 3 |
|
| 4 |
+
pipeline = DiffusionPipeline.from_pretrained("dataautogpt3/OpenDalleV1.1")
|
| 5 |
|
| 6 |
+
prompt = st.text_area("Enter your prompt here:")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
+
button = st.button("Generate Image")
|
|
|
|
| 9 |
|
| 10 |
+
if button:
|
| 11 |
+
if prompt != '':
|
| 12 |
+
image = pipeline.generate(prompt=prompt)
|
| 13 |
+
st.image(image, caption=f"Generated image from prompt: {prompt}")
|
| 14 |
+
else:
|
| 15 |
+
st.error("Please enter a prompt before generating an image.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|