Spaces:
Running
on
Zero
Running
on
Zero
killwithabass
commited on
Commit
•
d5cab33
1
Parent(s):
e7ccd2d
Update app.py
Browse files
app.py
CHANGED
@@ -1,12 +1,23 @@
|
|
1 |
import spaces
|
2 |
import gradio as gr
|
3 |
import torch
|
4 |
-
from PIL import Image
|
5 |
from diffusers import DiffusionPipeline
|
6 |
import random
|
7 |
import os
|
|
|
8 |
from datetime import datetime
|
9 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
# Initialize the base model and specific LoRA
|
11 |
base_model = "black-forest-labs/FLUX.1-dev"
|
12 |
pipe = DiffusionPipeline.from_pretrained(base_model, torch_dtype=torch.bfloat16)
|
@@ -53,14 +64,24 @@ def run_lora(prompt, cfg_scale, steps, randomize_seed, seed, width, height, lora
|
|
53 |
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
54 |
image_filename = f"generated_image_{timestamp}.png"
|
55 |
image_path = os.path.join("/tmp/gradio", image_filename)
|
56 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
57 |
|
58 |
# Construct the URL to access the image
|
59 |
space_url = "https://killwithabass-flux-1-dev-lora-androflux.hf.space" # Replace with your actual space URL
|
60 |
image_url = f"{space_url}/file={image_path}"
|
61 |
|
62 |
-
|
63 |
-
|
|
|
|
|
|
|
|
|
64 |
|
65 |
# Final update (100%)
|
66 |
progress(100, "Completed!")
|
|
|
1 |
import spaces
|
2 |
import gradio as gr
|
3 |
import torch
|
4 |
+
from PIL import Image, PngImagePlugin
|
5 |
from diffusers import DiffusionPipeline
|
6 |
import random
|
7 |
import os
|
8 |
+
import pygsheets
|
9 |
from datetime import datetime
|
10 |
|
11 |
+
# Initialize GSheet Connexion
|
12 |
+
#Authorization
|
13 |
+
gc = pygsheets.authorize(service_account_env_var='GSHEET_AUTH')
|
14 |
+
|
15 |
+
#Open the google spreadsheet
|
16 |
+
sh = gc.open('AndroFLUX-Logs')
|
17 |
+
|
18 |
+
#Select the first sheet
|
19 |
+
wks = sh[0]
|
20 |
+
|
21 |
# Initialize the base model and specific LoRA
|
22 |
base_model = "black-forest-labs/FLUX.1-dev"
|
23 |
pipe = DiffusionPipeline.from_pretrained(base_model, torch_dtype=torch.bfloat16)
|
|
|
64 |
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
65 |
image_filename = f"generated_image_{timestamp}.png"
|
66 |
image_path = os.path.join("/tmp/gradio", image_filename)
|
67 |
+
|
68 |
+
# Add Metadata
|
69 |
+
new_metadata_string = f"{prompt}\nNegative prompt: none \nSteps: {steps}, CFG scale: {cfg_scale}, Seed: {seed}, Lora hashes: AndroFlux-v19: c44afd41ece1"
|
70 |
+
metadata = PngImagePlugin.PngInfo()
|
71 |
+
metadata.add_text("parameters", new_metadata_string)
|
72 |
+
|
73 |
+
image.save(image_path, pnginfo=metadata)
|
74 |
|
75 |
# Construct the URL to access the image
|
76 |
space_url = "https://killwithabass-flux-1-dev-lora-androflux.hf.space" # Replace with your actual space URL
|
77 |
image_url = f"{space_url}/file={image_path}"
|
78 |
|
79 |
+
Log queries
|
80 |
+
try:
|
81 |
+
if "girl" not in prompt and "woman" not in prompt:
|
82 |
+
wks.append_table(values=[prompt, cfg_scale, steps, randomize_seed, seed, width, height, lora_scale,image_url])
|
83 |
+
except:
|
84 |
+
print(f"Image URL: {image_url}") # Log the file URL
|
85 |
|
86 |
# Final update (100%)
|
87 |
progress(100, "Completed!")
|