JarvisLabs commited on
Commit
3bd82ac
1 Parent(s): 200956a

Upload 9 files

Browse files
.env ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ REPLICATE_API_TOKEN="r8_Y2L8YCjCqtMnsoQDIfjZ9CL3Qllc9bH0M3nDY"
2
+ BB_KeyID="0056550b44687420000000001"
3
+ BB_AppKey= "K005EjPQyORkm9pYb97TKTqOLBFru3A"
4
+ BB_bucket="Saiseisei"
5
+ BB_defurl="https://f005.backblazeb2.com"
6
+ DEEPL_Key="27b13bc8-a639-95b0-74f0-ea97eeda58a5:fx"
7
+ email="saijapan2024@gmail.com"
8
+ email_pw="awlgsztnxsscjlcf"
.gitattributes CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ Tiles/4tile_20240115.png filter=lfs diff=lfs merge=lfs -text
Tiles/4tile_20240115.png ADDED

Git LFS Details

  • SHA256: 928482e9848644731d88f394e19bb7cdc169c433448874d66bad109b401b148a
  • Pointer size: 132 Bytes
  • Size of remote file: 2.41 MB
Tiles/Tile_20240123_1.jpg ADDED
Tiles/Tile_20240404.JPG ADDED
Tiles/Tile_20240421_1.jpg ADDED
Tiles/log.csv ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ img,promt,ps
2
+ ./Tiles/4tile_20240115.png,Green garden with a water water fountain and a river,0.6
3
+ ./Tiles/Tile_20240123_1.jpg,Outer space dust cloud,0.6
4
+ ./Tiles/Tile_20240404.JPG,Volcano,0.6
5
+ ./Tile_20240421_1.jpg,Outer space dust cloud with a small ship flying through,0.6
app.py ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from Saiseisei_workspace.utils import DeepL,Gen_image,send_email,base_model,example_data
3
+
4
+
5
+ model_dic={}
6
+ model_dic["None"]={
7
+ "model_loc":base_model,
8
+ "model_trigger":"high res, 4k",
9
+ }
10
+
11
+ model_dic["ISS MAP"]={
12
+ "model_loc":"jarvissan22/iss_nikond5:6ff0c8d11e33e4e8c91b1b9175a1c03f32fb559641bbbbe7007ac07b22fc5cec",
13
+ "model_trigger":"Aerial photo taken from the ISS photo taken from the ISS",
14
+ }
15
+
16
+
17
+ model_dic["Ukiyo-e_川瀬巴水"]={
18
+ "model_loc":"https://replicate.com/jarvissan22/kawasehasui_backgrounds",
19
+ "model_trigger":"Ukiyo-e,KawaseHasu",
20
+ }
21
+
22
+ model_dic["Anime_Galverse"]={
23
+ "model_loc":"galverse/setc-t1_label:65a7ee5a8c875fe9f38111699edf72f6c07f84dda7b7be5720e843ebb9f9c876",
24
+ "model_trigger":"anime coloring in the style of Galverse",
25
+ }
26
+
27
+ def gradio_gen_process(img,prompt,ps=0.6,style_model=None,ls=0.6,jp=None,recipient_email=None,model=base_model,model_trigger=None,save_loc=save_loc):
28
+ #JP Detect
29
+ if jp:
30
+ prompt=DeepL(prompt)
31
+ if style_model:
32
+ model=model_dic[style_model]["model_loc"]
33
+ model_trigger=model_dic[style_model]["model_trigger"]
34
+
35
+ if model_trigger:
36
+ prompt+=", "+model_trigger
37
+ if type(ps)==str: # error on example detail: - input.prompt_strength: Invalid type. Expected: number, given: string
38
+ ps=float(ps)
39
+
40
+ #Image gen
41
+ print(img)
42
+ img,file_saveloc=Gen_image(prompt,img=img,ps=ps,lr=ls,model=model,save_loc=save_loc)
43
+
44
+ #Send email
45
+ if recipient_email:
46
+ send_email(file_saveloc,recipient_email,prompt=prompt)
47
+ print("Email sent to ",recipient_email)
48
+ else:
49
+ print("Email not sent")
50
+
51
+ return img
52
+
53
+
54
+
55
+ output_placeholder = gr.Label()
56
+ gradio_interface=gr.Interface(
57
+ fn=gradio_gen_process,
58
+ inputs=[
59
+ gr.Image(value=example_data[0]["img"],type="filepath"),
60
+ gr.Textbox(label="Prompt"),
61
+ gr.Slider(minimum=0.1,maximum=1,value=0.6,label="PS:Image > Prompt"),
62
+ gr.Dropdown(list(model_dic.keys()),label="Style model"),
63
+ gr.Slider(minimum=0.1,maximum=1,value=0.6,label="LS:Style strength"),
64
+ gr.Checkbox(label="日本語", info="Promtは日本語ですか?"),
65
+ gr.Textbox(label="Email",placeholder="")
66
+ ],
67
+ outputs=[
68
+ gr.Image(label="gened image",type="pil")
69
+ ],
70
+ examples=img_loc
71
+ )
72
+ gradio_interface.launch(debug=True,share=True)
requirments.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ replicate==0.25.1
2
+ gradio==4.26.0
3
+ b2sdk==2.0.0
4
+ dotenv-python
utils.py ADDED
@@ -0,0 +1,171 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+
3
+ from IPython.display import display
4
+ from PIL import Image
5
+ import glob
6
+ import gradio as gr
7
+ import warnings
8
+ import io
9
+ import pandas as pd
10
+ import replicate
11
+ import json
12
+ import requests
13
+ import os
14
+ from datetime import date
15
+ import secrets
16
+ import string
17
+ import b2sdk.v2 as b2 #Backblaze img2img upload bucket
18
+ import os
19
+ import requests
20
+ from dotenv import load_dotenv, find_dotenv
21
+ _ = load_dotenv(find_dotenv())
22
+
23
+
24
+ ## Backclaze
25
+ info = b2.InMemoryAccountInfo()
26
+ b2_api = b2.B2Api(info)
27
+ application_key_id = os.getenv("BB_KeyID")
28
+ application_key = os.getenv("BB_AppKey")
29
+ #print(application_key_id,application_key)
30
+ b2_api.authorize_account("production", application_key_id, application_key)
31
+ BB_bucket_name=os.getenv("BB_bucket")
32
+ BB_bucket=b2_api.get_bucket_by_name(os.getenv("BB_bucket"))
33
+ BB_defurl=os.getenv("BB_defurl")
34
+
35
+
36
+ def BB_uploadfile(local_file,file_name,b2_api=b2_api,BB_bucket_name=BB_bucket_name,FRIENDLY_URL=True):
37
+ metadata = {"key": "value"}
38
+ uploaded_file = BB_bucket.upload_local_file(
39
+ local_file=local_file,
40
+ file_name=file_name,
41
+ file_infos=metadata,
42
+ )
43
+ img_url=b2_api.get_download_url_for_fileid(uploaded_file.id_)
44
+ if FRIENDLY_URL: #Get friendly URP
45
+ img_url=BB_defurl+"/file/"+BB_bucket_name+"/"+file_name
46
+ print("backblaze", img_url)
47
+ return img_url
48
+
49
+
50
+ #deepL api
51
+
52
+ def DeepL(text,source_lang="JA",target_lang="EN",API_KEY= os.getenv("DEEPL_Key")):
53
+ # パラメータの指定
54
+ params = {
55
+ 'auth_key' : API_KEY,
56
+ 'text' : text,
57
+ 'source_lang' : source_lang, # 翻訳対象の言語
58
+ "target_lang": target_lang # 翻訳後の言語
59
+ }
60
+ # リクエストを投げる
61
+ request = requests.post("https://api-free.deepl.com/v2/translate", data=params) # URIは有償版, 無償版で異なるため要注意
62
+ result = request.json()
63
+ return result["translations"][0]["text"]
64
+
65
+ ##Email client
66
+
67
+ import smtplib
68
+ from email.mime.multipart import MIMEMultipart
69
+ from email.mime.text import MIMEText
70
+ from email.mime.image import MIMEImage
71
+ from email.utils import formatdate
72
+
73
+
74
+
75
+ def send_email(image_path, recipient_email,prompt=None,email=os.getenv("email"),pw=os.getenv("email_pw")):
76
+ sender_email = email
77
+ password = pw
78
+ msg = MIMEMultipart()
79
+ msg['From'] = sender_email
80
+ msg['To'] = recipient_email
81
+ msg['Subject'] =f"「Saiseisei Generated Image」: {os.path.basename(image_path)}"
82
+ msg['Date'] = formatdate()
83
+ # Attach prompt
84
+ Text=f"""
85
+ 再生成のワークショップをご参加ありがとうございました
86
+ 生成したAI画像はこのメールに添付しました。
87
+ --
88
+ file name: {os.path.basename(image_path)}
89
+ prompt: {prompt}
90
+ --
91
+ 再生成について最も知りたいなら、IGで@pp_yokoと@jarvis_labsを連絡してください
92
+ https://www.instagram.com/jarvis_labs/
93
+ https://www.instagram.com/pp_yoko/
94
+ --
95
+ そして、SNSで画像を共有したいなら、ぜひしてお願いいたします
96
+ よろしくお願いいたします。
97
+ Jarvis
98
+
99
+ """
100
+ msg.attach(MIMEText(Text, 'plain', 'utf-8'))
101
+ # Attach the image
102
+ with open(image_path, 'rb') as f:
103
+ img = MIMEImage(f.read())
104
+ msg.attach(img)
105
+ server = smtplib.SMTP('smtp.gmail.com', 587) #smtp_server = "smtp.gmail.com" Google
106
+ server.ehlo()
107
+ server.starttls()
108
+ server.ehlo()
109
+ server.login(sender_email, password)
110
+
111
+ server.send_message(msg)
112
+ server.quit()
113
+
114
+
115
+ #Other
116
+ def random_str(n=8):
117
+ # Define the characters to choose from
118
+ characters = string.ascii_letters + string.digits
119
+ # Generate the unreplicable string of length 8
120
+ unreplicable_string = ''.join(secrets.choice(characters) for _ in range(n))
121
+ return unreplicable_string
122
+
123
+
124
+ #Replicate img gen
125
+ base_model="lucataco/sdxl:c86579ac5193bf45422f1c8b92742135aa859b1850a8e4c531bff222fc75273d"
126
+
127
+ img_loc="./Tiles/"
128
+ example_data=[]
129
+ example_data.append({"img":img_loc+"4tile_20240115.png","promt":"Green garden with a water water fountain and a river","ps":0.6})
130
+ example_data.append({"img":img_loc+"Tile_20240123_1.jpg","promt": "Outer space dust cloud","ps":0.6})
131
+ example_data.append({"img":img_loc+"Tile_20240404.JPG","promt": "Volcano","ps":0.6})
132
+ example_data.append({"img":img_loc+"Tile_20240421_1.jpg","promt": "Outer space dust cloud with a small ship flying through","ps":0.6})
133
+
134
+ #"jarvissan22/kawasehasui_backgrounds:a4bb8bb1beb503b02c93789381544097dcb70afc92c512ea1500e70ccf704bc4"
135
+ def Gen_image(prompt,img=None,ps=0.7,lr=0.8,model=base_model,save_loc="",w=1024,h=1024):
136
+ input={
137
+ "width": w,
138
+ "height": h,
139
+ "prompt": prompt,
140
+ "refine": "no_refiner",
141
+ "scheduler": "K_EULER",
142
+ "lora_scale": lr,
143
+ "num_outputs": 1,
144
+ "guidance_scale": 7.5,
145
+ "apply_watermark": True,
146
+ "high_noise_frac": 0.8,
147
+ "negative_prompt": "",
148
+ "prompt_strength": ps,
149
+ "num_inference_steps": 50
150
+ }
151
+
152
+ if img: #Upload image to backblaze
153
+ img_url=BB_uploadfile(img,os.path.basename(img))
154
+ input["image"]=img_url
155
+
156
+ #Gen image
157
+ output = replicate.run(
158
+ model,
159
+ input=input,
160
+ )
161
+ #Get image
162
+ img_url=output[0]
163
+ r=requests.get(img_url)
164
+ image = Image.open(io.BytesIO(r.content))
165
+ #Save image
166
+ file_saveloc=os.path.join(save_loc,f"GenImage_{date.today().strftime('%Y-%m-%d')}_{random_str()}.jpg")
167
+ image.save(file_saveloc)
168
+ #Upload image to backblaze
169
+ _=BB_uploadfile(file_saveloc,os.path.basename(file_saveloc))
170
+
171
+ return image,file_saveloc