Spaces:
Sleeping
Sleeping
Andre
commited on
Commit
·
3a8b155
1
Parent(s):
03f95f8
Bug fix
Browse files- .gitignore +2 -0
- README.md +1 -1
- config/__pycache__/config.cpython-311.pyc +0 -0
- config/__pycache__/models.cpython-311.pyc +0 -0
- config/__pycache__/prompts.cpython-311.pyc +0 -0
- close.py → old/close.py +0 -0
- src/__pycache__/gradio_interface.cpython-311.pyc +0 -0
- src/__pycache__/img_gen.cpython-311.pyc +0 -0
- src/gradio_interface.py +20 -16
- src/img_gen.py +19 -3
- temp +8 -0
.gitignore
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
images/
|
| 2 |
+
.venv/
|
README.md
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
---
|
| 2 |
-
title: CtB
|
| 3 |
emoji: 🏰
|
| 4 |
colorFrom: green
|
| 5 |
colorTo: indigo
|
|
|
|
| 1 |
---
|
| 2 |
+
title: CtB-AI-castles-hp
|
| 3 |
emoji: 🏰
|
| 4 |
colorFrom: green
|
| 5 |
colorTo: indigo
|
config/__pycache__/config.cpython-311.pyc
ADDED
|
Binary file (270 Bytes). View file
|
|
|
config/__pycache__/models.cpython-311.pyc
ADDED
|
Binary file (515 Bytes). View file
|
|
|
config/__pycache__/prompts.cpython-311.pyc
ADDED
|
Binary file (2.89 kB). View file
|
|
|
close.py → old/close.py
RENAMED
|
File without changes
|
src/__pycache__/gradio_interface.cpython-311.pyc
ADDED
|
Binary file (2.23 kB). View file
|
|
|
src/__pycache__/img_gen.cpython-311.pyc
ADDED
|
Binary file (2.92 kB). View file
|
|
|
src/gradio_interface.py
CHANGED
|
@@ -4,31 +4,35 @@ from src.img_gen import generate_image
|
|
| 4 |
|
| 5 |
|
| 6 |
# Gradio Interface
|
| 7 |
-
def generate_interface(left_hp, right_hp):
|
| 8 |
-
|
| 9 |
-
|
| 10 |
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
|
| 20 |
# Gradio UI Components
|
| 21 |
with gr.Blocks() as demo:
|
| 22 |
-
gr.Markdown("# CtB
|
| 23 |
with gr.Row():
|
| 24 |
left_hp = gr.Slider(0, 100, value=100, label="Left Castle HP")
|
| 25 |
right_hp = gr.Slider(0, 100, value=100, label="Right Castle HP")
|
| 26 |
-
|
| 27 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
|
| 29 |
# Link the button to the function
|
| 30 |
generate_button.click(
|
| 31 |
-
|
| 32 |
inputs=[left_hp, right_hp],
|
| 33 |
-
outputs=output_image
|
| 34 |
)
|
|
|
|
| 4 |
|
| 5 |
|
| 6 |
# Gradio Interface
|
| 7 |
+
# def generate_interface(left_hp, right_hp):
|
| 8 |
+
# # Generate the image
|
| 9 |
+
# image = generate_image(left_hp, right_hp)
|
| 10 |
|
| 11 |
+
# if isinstance(image, str):
|
| 12 |
+
# return image # Return error message
|
| 13 |
+
# else:
|
| 14 |
+
# # Save the image with a timestamped filename
|
| 15 |
+
# timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
| 16 |
+
# output_filename = f"{timestamp}_left_{left_hp}_right_{right_hp}.png"
|
| 17 |
+
# image.save(output_filename)
|
| 18 |
+
# return output_filename
|
| 19 |
|
| 20 |
# Gradio UI Components
|
| 21 |
with gr.Blocks() as demo:
|
| 22 |
+
gr.Markdown("# ========== CtB AI Castle HP ==========")
|
| 23 |
with gr.Row():
|
| 24 |
left_hp = gr.Slider(0, 100, value=100, label="Left Castle HP")
|
| 25 |
right_hp = gr.Slider(0, 100, value=100, label="Right Castle HP")
|
| 26 |
+
with gr.Row():
|
| 27 |
+
generate_button = gr.Button("Generate Image")
|
| 28 |
+
with gr.Row():
|
| 29 |
+
output_image = gr.Image(label="Generated Image")
|
| 30 |
+
with gr.Row():
|
| 31 |
+
status_text = gr.Textbox(label="Status", placeholder="Waiting for input...", interactive=False)
|
| 32 |
|
| 33 |
# Link the button to the function
|
| 34 |
generate_button.click(
|
| 35 |
+
generate_image,
|
| 36 |
inputs=[left_hp, right_hp],
|
| 37 |
+
outputs=[output_image, status_text]
|
| 38 |
)
|
src/img_gen.py
CHANGED
|
@@ -3,12 +3,13 @@ from config.prompts import generate_prompt
|
|
| 3 |
from huggingface_hub import InferenceClient
|
| 4 |
from config.models import models
|
| 5 |
from config.config import api_token
|
|
|
|
| 6 |
|
| 7 |
# Function to generate images based on the HP values
|
| 8 |
def generate_image(left_hp, right_hp):
|
| 9 |
# Hardcoded parameters
|
| 10 |
-
height = 512 # Fixed height
|
| 11 |
width = 1024 # Fixed width
|
|
|
|
| 12 |
num_inference_steps = 20 # Fixed inference steps
|
| 13 |
guidance_scale = 2.0 # Fixed guidance scale
|
| 14 |
seed = random.randint(0, 1000000) # Random seed
|
|
@@ -44,6 +45,21 @@ def generate_image(left_hp, right_hp):
|
|
| 44 |
print(f"Guidance Scale: {guidance_scale}")
|
| 45 |
print(f"Seed: {seed}")
|
| 46 |
|
| 47 |
-
return image
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
except Exception as e:
|
| 49 |
-
return f"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
from huggingface_hub import InferenceClient
|
| 4 |
from config.models import models
|
| 5 |
from config.config import api_token
|
| 6 |
+
from datetime import datetime
|
| 7 |
|
| 8 |
# Function to generate images based on the HP values
|
| 9 |
def generate_image(left_hp, right_hp):
|
| 10 |
# Hardcoded parameters
|
|
|
|
| 11 |
width = 1024 # Fixed width
|
| 12 |
+
height = 512 # Fixed height
|
| 13 |
num_inference_steps = 20 # Fixed inference steps
|
| 14 |
guidance_scale = 2.0 # Fixed guidance scale
|
| 15 |
seed = random.randint(0, 1000000) # Random seed
|
|
|
|
| 45 |
print(f"Guidance Scale: {guidance_scale}")
|
| 46 |
print(f"Seed: {seed}")
|
| 47 |
|
| 48 |
+
#return image
|
| 49 |
+
except Exception as e:
|
| 50 |
+
return None, f"An error occurred: {e}"
|
| 51 |
+
|
| 52 |
+
# Save the image with a timestamped filename
|
| 53 |
+
print("-----SAVING-----", image)
|
| 54 |
+
path = "images"
|
| 55 |
+
|
| 56 |
+
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
| 57 |
+
output_filename = f"{path}/{timestamp}_{seed}_left_{left_hp}_right_{right_hp}.png"
|
| 58 |
+
try:
|
| 59 |
+
image.save(output_filename)
|
| 60 |
except Exception as e:
|
| 61 |
+
return None, f"ERROR: Failed to save image. Details: {e}"
|
| 62 |
+
print("-----DONE!-----")
|
| 63 |
+
print("-----CALL THE BANNERS!-----")
|
| 64 |
+
|
| 65 |
+
return output_filename, "Image generated successfully! Call the banners!"
|
temp
CHANGED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# colab.ipynb
|
| 2 |
+
import sys
|
| 3 |
+
import os
|
| 4 |
+
|
| 5 |
+
# Add the root folder to the Python path
|
| 6 |
+
root_path = os.path.abspath("")
|
| 7 |
+
if root_path not in sys.path:
|
| 8 |
+
sys.path.append(root_path)
|