Leeps commited on
Commit
1dda0cc
·
verified ·
1 Parent(s): 2e2d8c0

Upload folder using huggingface_hub

Browse files
Files changed (4) hide show
  1. .gitignore +13 -0
  2. README.md +2 -8
  3. index.py +107 -0
  4. requirements.txt +2 -0
.gitignore ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .vercel
2
+ *.log
3
+ *.pyc
4
+ __pycache__
5
+
6
+ # Environments
7
+ .env
8
+ .venv
9
+ env/
10
+ venv/
11
+ ENV/
12
+ env.bak/
13
+ venv.bak/
README.md CHANGED
@@ -1,12 +1,6 @@
1
  ---
2
- title: Teenage Engineering
3
- emoji: 🐢
4
- colorFrom: indigo
5
- colorTo: purple
6
  sdk: gradio
7
  sdk_version: 4.36.1
8
- app_file: app.py
9
- pinned: false
10
  ---
11
-
12
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
  ---
2
+ title: teenage-engineering
3
+ app_file: index.py
 
 
4
  sdk: gradio
5
  sdk_version: 4.36.1
 
 
6
  ---
 
 
index.py ADDED
@@ -0,0 +1,107 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import base64
3
+ import numpy as np
4
+ from PIL import Image
5
+ import io
6
+ import requests
7
+ import gradio as gr
8
+
9
+ import replicate
10
+
11
+ from dotenv import load_dotenv, find_dotenv
12
+
13
+ # Locate the .env file
14
+ dotenv_path = find_dotenv()
15
+
16
+ load_dotenv(dotenv_path)
17
+
18
+ REPLICATE_API_TOKEN = os.getenv('REPLICATE_API_TOKEN')
19
+
20
+
21
+ def image_classifier(prompt, starter_image, image_strength):
22
+
23
+ if starter_image is not None:
24
+ starter_image_pil = Image.fromarray(starter_image.astype('uint8'))
25
+
26
+ # Resize the starter image if either dimension is larger than 768 pixels
27
+ if starter_image_pil.size[0] > 512 or starter_image_pil.size[1] > 512:
28
+ # Calculate the new size while maintaining the aspect ratio
29
+ if starter_image_pil.size[0] > starter_image_pil.size[1]:
30
+ # Width is larger than height
31
+ new_width = 512
32
+ new_height = int((512 / starter_image_pil.size[0]) * starter_image_pil.size[1])
33
+ else:
34
+ # Height is larger than width
35
+ new_height = 512
36
+ new_width = int((512 / starter_image_pil.size[1]) * starter_image_pil.size[0])
37
+
38
+ # Resize the image
39
+ starter_image_pil = starter_image_pil.resize((new_width, new_height), Image.LANCZOS)
40
+
41
+ # Save the starter image to a bytes buffer
42
+ buffered = io.BytesIO()
43
+ starter_image_pil.save(buffered, format="JPEG")
44
+
45
+ # Encode the starter image to base64
46
+ starter_image_base64 = base64.b64encode(buffered.getvalue()).decode('utf-8')
47
+
48
+ if starter_image is not None:
49
+ input = {
50
+ "prompt": prompt + " in the style of TOK",
51
+ "negative_prompt": "worst quality, low quality, illustration, 2d, painting, cartoons, sketch",
52
+ "apply_watermark": False,
53
+ "num_inference_steps": 25,
54
+ #"refine": "expert_ensemble_refiner",
55
+ "num_outputs": 3,
56
+ "lora_scale": .9,
57
+ "image": "data:image/jpeg;base64," + starter_image_base64,
58
+ "prompt_strength": 1-image_strength,
59
+ }
60
+ else:
61
+ input = {
62
+ "width": 512,
63
+ "height": 512,
64
+ "prompt": prompt + " in the style of TOK",
65
+ "negative_prompt": "worst quality, low quality, illustration, 2d, painting, cartoons, sketch",
66
+ "apply_watermark": False,
67
+ "num_inference_steps": 50,
68
+ "num_outputs": 3,
69
+ "scheduler": "DDIM",
70
+ "refine": "expert_ensemble_refiner",
71
+ "lora_scale": .85,
72
+ }
73
+
74
+ output = replicate.run(
75
+ # update to new trained model
76
+ "ltejedor/teenage-engineering:8a7c93ece9c7a4ae76e08c013f1b4bf25bb3258fa549d112b9f90766d9defb92",
77
+ input=input
78
+ )
79
+
80
+ print(output)
81
+
82
+ # Download the image from the URL
83
+ image_url = output[0]
84
+ print(image_url)
85
+ response = requests.get(image_url)
86
+ print(response)
87
+ img1 = Image.open(io.BytesIO(response.content))
88
+
89
+ # Download the image from the URL
90
+ image_url = output[1]
91
+ print(image_url)
92
+ response = requests.get(image_url)
93
+ print(response)
94
+ img2 = Image.open(io.BytesIO(response.content))
95
+
96
+ # Download the image from the URL
97
+ image_url = output[2]
98
+ print(image_url)
99
+ response = requests.get(image_url)
100
+ print(response)
101
+ img3 = Image.open(io.BytesIO(response.content))
102
+
103
+ return [img1, img2, img3]
104
+
105
+
106
+ demo = gr.Interface(fn=image_classifier, inputs=["text", "image", gr.Slider(0, 1, step=0.025, value=0.2, label="Image Strength")], outputs=["image", "image", "image"])
107
+ demo.launch(share=False)
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ replicate
2
+ gradio