Spaces:
Sleeping
Sleeping
File size: 1,270 Bytes
31b3285 110b7d6 31b3285 110b7d6 349bb4d 110b7d6 349bb4d 3d74153 110b7d6 6f473bc 7d671a1 110b7d6 6f473bc 31b3285 6f473bc 110b7d6 6f473bc 31b3285 |
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 40 41 42 |
import streamlit as st
from diffusers import DiffusionPipeline
# Load the Diffusion pipeline
@st.cache(allow_output_mutation=True)
def load_diffusion_pipeline():
try:
pipeline = DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-3-medium")
return pipeline
except Exception as e:
st.error(f"Error loading model: {e}")
def generate_response(prompt_text, pipeline):
try:
response = pipeline(prompt_text, top_p=0.9, max_length=100)[0]['generated_text']
return response
except Exception as e:
st.error(f"Error generating response: {e}")
def main():
st.title('Hugging Face Diffusion Model')
# Load the model
pipeline = load_diffusion_pipeline()
# Text input for the prompt
prompt_text = st.text_area("Enter your prompt here:", height=200)
# Button to generate prompt
if st.button("Generate"):
if prompt_text:
with st.spinner('Generating...'):
generated_text = generate_response(prompt_text, pipeline)
st.success('Generation complete!')
st.text_area('Generated Text:', value=generated_text, height=400)
else:
st.warning('Please enter a prompt.')
if __name__ == '__main__':
main()
|