ProfessorLeVesseur commited on
Commit
b7c83d7
·
verified ·
1 Parent(s): a3f9924

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -4
app.py CHANGED
@@ -39,12 +39,35 @@ def generate_images(prompt): #def generate_images(image_description, num_images)
39
  image_url = response.data[0].url
40
  return image_url
41
 
42
- prompt = st.text_area("Enter a description for the image you want to generate")
 
 
 
 
 
 
 
 
 
43
 
44
- #create a button
45
  if st.button("Generate Images"):
46
  with st.spinner("Analyzing the image ..."):
47
- generate_image=generate_images(prompt) #generate_image=generate_images(prompt, num_of_images)
48
- st.image(generate_image)
 
 
 
 
49
 
 
 
 
 
 
 
 
 
 
 
 
50
 
 
39
  image_url = response.data[0].url
40
  return image_url
41
 
42
+ # prompt = st.text_area("Enter a description for the image you want to generate")
43
+
44
+ # #create a button
45
+ # if st.button("Generate Images"):
46
+ # with st.spinner("Analyzing the image ..."):
47
+ # generate_image=generate_images(prompt) #generate_image=generate_images(prompt, num_of_images)
48
+ # st.image(generate_image)
49
+
50
+ # Use a unique key for the text area to avoid conflicts with other session_state usages
51
+ image_description_prompt = st.text_area("Enter a description for the image you want to generate", key="image_description")
52
 
 
53
  if st.button("Generate Images"):
54
  with st.spinner("Analyzing the image ..."):
55
+ # Generate the image and store its URL in session_state
56
+ st.session_state['generated_image_url'] = generate_images(image_description_prompt)
57
+
58
+ # Check if the 'generated_image_url' key exists in session_state and display the image and download button
59
+ if 'generated_image_url' in st.session_state and st.session_state['generated_image_url']:
60
+ st.image(st.session_state['generated_image_url'], caption="Generated Image")
61
 
62
+ # Fetch the image from the URL to enable downloading
63
+ response = requests.get(st.session_state['generated_image_url'])
64
+ if response.status_code == 200:
65
+ img_bytes = BytesIO(response.content)
66
+ st.download_button(
67
+ label="Download Image",
68
+ data=img_bytes,
69
+ file_name="generated_image.png",
70
+ mime="image/png"
71
+ )
72
+ st.success('Powered by MTSS GPT. AI can make mistakes. Consider checking important information.')
73