Spaces:
Sleeping
Sleeping
Create src/config.py
Browse files- src/config.py +28 -0
src/config.py
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import mimetypes
|
| 3 |
+
|
| 4 |
+
def read_system_prompt(file_path: str) -> str:
|
| 5 |
+
with open(file_path, 'r', encoding='utf-8') as file:
|
| 6 |
+
return file.read()
|
| 7 |
+
|
| 8 |
+
def load_prompt_template(base_image_path: str, user_instruction: str) -> str:
|
| 9 |
+
base_prompt = read_system_prompt('prompt.txt')
|
| 10 |
+
enriched_prompt = base_prompt.format(
|
| 11 |
+
base_image_path=base_image_path,
|
| 12 |
+
user_instruction=user_instruction
|
| 13 |
+
)
|
| 14 |
+
return enriched_prompt.strip()
|
| 15 |
+
|
| 16 |
+
def save_image(file_name: str, data: bytes):
|
| 17 |
+
with open(file_name, "wb") as f:
|
| 18 |
+
f.write(data)
|
| 19 |
+
print(f"Fichier sauvegardé : {file_name}")
|
| 20 |
+
|
| 21 |
+
def save_image(user_text, file_name, data):
|
| 22 |
+
sanitized_user_text = user_text[:10].replace(" ", "_").lower()
|
| 23 |
+
new_file_name = f"genere_pour_{sanitized_user_text}_{file_name}"
|
| 24 |
+
file_path = os.path.join("generated_image", new_file_name)
|
| 25 |
+
os.makedirs("generated_image", exist_ok=True)
|
| 26 |
+
with open(file_path, "wb") as f:
|
| 27 |
+
f.write(data)
|
| 28 |
+
print(f"Image générée : {file_path}")
|