Spaces:
Build error
Build error
mookkanvas
commited on
Commit
·
725566b
1
Parent(s):
d3e1bc0
Update app.py
Browse files
app.py
CHANGED
@@ -1,50 +1,24 @@
|
|
1 |
-
import streamlit as st
|
2 |
-
from
|
3 |
-
import
|
4 |
-
import openai
|
5 |
-
from diffusers import StableDiffusionPipeline
|
6 |
-
import torch
|
7 |
|
8 |
-
|
9 |
-
|
10 |
|
11 |
-
#
|
12 |
-
|
13 |
-
response = openai.Image.create(prompt= text, n=1, size="512x512")
|
14 |
-
image_url = response['data'][0]['url']
|
15 |
-
return image_url
|
16 |
|
|
|
|
|
17 |
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
prompt = text
|
23 |
-
image = pipe(prompt).images[0]
|
24 |
-
return image
|
25 |
|
26 |
-
#
|
27 |
-
|
28 |
|
29 |
-
|
30 |
-
st.
|
31 |
-
|
32 |
-
st.write("This is a simple image generation app that uses AI to generates images from text prompt.")
|
33 |
-
|
34 |
-
elif choice == "DALL-E":
|
35 |
-
st.subheader("Image generation using Open AI's DALL-E")
|
36 |
-
input_prompt = st.text_input("Enter your text prompt")
|
37 |
-
if input_prompt is not None:
|
38 |
-
if st.button("Generate Image"):
|
39 |
-
image_url = generate_images_using_openai(input_prompt)
|
40 |
-
st.image(image_url, caption="Generated by DALL-E")
|
41 |
-
|
42 |
-
elif choice == "Huggingface Diffusers":
|
43 |
-
st.subheader("Image generation using Huggingface Diffusers")
|
44 |
-
input_prompt = st.text_input("Enter your text prompt")
|
45 |
-
if input_prompt is not None:
|
46 |
-
if st.button("Generate Image"):
|
47 |
-
image_output = generate_images_using_huggingface_diffusers(input_prompt)
|
48 |
-
st.info("Generating image.....")
|
49 |
-
st.success("Image Generated Successfully")
|
50 |
-
st.image(image_output, caption="Generated by Huggingface Diffusers")
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from PIL import Image
|
3 |
+
from transformers import pipeline
|
|
|
|
|
|
|
4 |
|
5 |
+
# Create an image captioning pipeline using Hugging Face Transformers
|
6 |
+
image_captioner = pipeline("image-captioning")
|
7 |
|
8 |
+
# Streamlit app header
|
9 |
+
st.title("Hugging Face Transformer Image-to-Text App")
|
|
|
|
|
|
|
10 |
|
11 |
+
# File uploader for image
|
12 |
+
uploaded_image = st.file_uploader("Upload an image", type=["jpg", "png", "jpeg"])
|
13 |
|
14 |
+
if uploaded_image:
|
15 |
+
# Display the uploaded image
|
16 |
+
image = Image.open(uploaded_image)
|
17 |
+
st.image(image, caption="Uploaded Image", use_column_width=True)
|
|
|
|
|
|
|
18 |
|
19 |
+
# Perform image captioning when an image is uploaded
|
20 |
+
caption = image_captioner(uploaded_image)[0]["caption"]
|
21 |
|
22 |
+
# Display the generated caption
|
23 |
+
st.subheader("Generated Caption:")
|
24 |
+
st.write(caption)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|