ankur2402 commited on
Commit
0aff13e
1 Parent(s): aab7a84

Upload 2 files

Browse files
Files changed (2) hide show
  1. main.py +64 -0
  2. requirements.txt +4 -0
main.py ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pandas as pd
2
+ import streamlit as st
3
+ from PIL import Image
4
+ # from streamlit_drawable_canvas import st_canvas
5
+ import replicate
6
+ from pathlib import Path
7
+ # Import the 'replicate' module, which likely contains functions for running AI models or tasks.
8
+ import replicate
9
+ import urllib.request
10
+ from pathlib import Path
11
+ import os
12
+ from PIL import Image
13
+
14
+
15
+ st.title("StyleSnap")
16
+
17
+ with st.sidebar:
18
+ with st.form('Replicate'):
19
+ # User selects the model (OpenAI/Cohere) and enters API keys
20
+ rep_key = st.text_input('Enter Replicate Key', type="password")
21
+ submitted = st.form_submit_button("Submit")
22
+
23
+ if rep_key:
24
+ os.environ["REPLICATE_API_TOKEN"] = rep_key
25
+
26
+
27
+ def resize_image(image, size):
28
+ img = Image.open(image)
29
+ img_resized = img.resize(size, Image.LANCZOS)
30
+ return img_resized
31
+
32
+ def gen(path,prompt,clothing):
33
+ output = replicate.run(
34
+ "naklecha/fashion-ai:4e7916cc6ca0fe2e0e414c32033a378ff5d8879f209b1df30e824d6779403826",
35
+ input={"image": open(path,'rb'),
36
+ "clothing": clothing,
37
+ "prompt": prompt}
38
+ )
39
+ urllib.request.urlretrieve(output[-1], "image.png")
40
+ image = Image.open("image.png")
41
+ st.image(image)
42
+ image.save("inpainting.png")
43
+
44
+ clothing = [
45
+ "topwear",
46
+ "bottomwear"
47
+ ]
48
+ clothing = st.selectbox("Select clothing", clothing)
49
+ prompt = st.text_input('Enter prompt')
50
+
51
+ uploaded_file = st.file_uploader(f"Upload image:", type=['png','jpg'])
52
+
53
+ if (st.button("Submit")):
54
+ if uploaded_file is not None:
55
+ st.write("File uploaded successfully!")
56
+ file_contents = uploaded_file.read()
57
+ save_path = uploaded_file.name
58
+ # image = Image.open(uploaded_file)
59
+ resized_size = (512, 512)
60
+ resized_image = resize_image(uploaded_file, resized_size)
61
+ st.image(resized_image, caption="Uploaded Image", use_column_width=True)
62
+ resized_image.save(save_path)
63
+ gen(save_path,prompt,clothing)
64
+
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ streamlit==1.3.1
2
+ Pillow==8.4.0
3
+ replicate~=0.8.3
4
+ utils~=1.0.1