Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -86,7 +86,7 @@ NEVER output "name" and "json" wrapper format.
|
|
| 86 |
For Builder JSON, output ONLY the pure JSON object.
|
| 87 |
|
| 88 |
For code blocks, use appropriate language tags:
|
| 89 |
-
|
| 90 |
php
|
| 91 |
// PHP code here
|
| 92 |
css
|
|
@@ -95,7 +95,7 @@ javascript
|
|
| 95 |
// JavaScript code here
|
| 96 |
For images, use the exact format:
|
| 97 |
[GENERATE_IMAGE: "detailed prompt description"]
|
| 98 |
-
|
| 99 |
BEHAVIOR:
|
| 100 |
|
| 101 |
You are arrogant but highly competent.
|
|
@@ -109,7 +109,7 @@ Always validate your JSON structure before outputting.
|
|
| 109 |
Strip all explanatory text when outputting Builder JSON.
|
| 110 |
"""
|
| 111 |
|
| 112 |
-
=== 4. CORE UTILITIES ===
|
| 113 |
class AlchemyUtils:
|
| 114 |
@staticmethod
|
| 115 |
def extract_image_prompts(text: str) -> List[str]:
|
|
@@ -147,7 +147,8 @@ def extract_code_blocks(text: str) -> Dict[str, str]:
|
|
| 147 |
@staticmethod
|
| 148 |
def format_timestamp() -> str:
|
| 149 |
return datetime.now().isoformat()
|
| 150 |
-
|
|
|
|
| 151 |
class AsyncRateLimiter:
|
| 152 |
def init(self, rpm: int):
|
| 153 |
self.rate = rpm
|
|
@@ -195,7 +196,8 @@ async def set(self, key: str, value: str) -> None:
|
|
| 195 |
|
| 196 |
def get_stats(self) -> Dict[str, int]:
|
| 197 |
return {"size": len(self.cache), "hits": self.hits, "misses": self.misses}
|
| 198 |
-
|
|
|
|
| 199 |
class ImageGenerator:
|
| 200 |
def init(self, client: AsyncInferenceClient):
|
| 201 |
self.client = client
|
|
@@ -299,7 +301,7 @@ async def chat_stream(self, message: str, history: List[Dict]) -> AsyncGenerator
|
|
| 299 |
except Exception as e:
|
| 300 |
logger.error(f"Stream Exception: {e}")
|
| 301 |
yield f"β **Transmutation Failed:** {str(e)}\n\n*Check the logs for stack trace.*"
|
| 302 |
-
=== 7. UI COMPONENT ARCHITECTURE ===
|
| 303 |
class UIBuilder:
|
| 304 |
@staticmethod
|
| 305 |
def get_custom_css() -> str:
|
|
@@ -374,7 +376,7 @@ def render_header():
|
|
| 374 |
</div>
|
| 375 |
</div>
|
| 376 |
"""
|
| 377 |
-
=== 8. APPLICATION FACTORY ===
|
| 378 |
def create_demo() -> gr.Blocks:
|
| 379 |
agent = AlchemyAgent()
|
| 380 |
|
|
@@ -438,7 +440,7 @@ with gr.Blocks(
|
|
| 438 |
""")
|
| 439 |
|
| 440 |
return demo
|
| 441 |
-
=== 9. ENTRY POINT ===
|
| 442 |
def main():
|
| 443 |
try:
|
| 444 |
demo = create_demo()
|
|
|
|
| 86 |
For Builder JSON, output ONLY the pure JSON object.
|
| 87 |
|
| 88 |
For code blocks, use appropriate language tags:
|
| 89 |
+
```
|
| 90 |
php
|
| 91 |
// PHP code here
|
| 92 |
css
|
|
|
|
| 95 |
// JavaScript code here
|
| 96 |
For images, use the exact format:
|
| 97 |
[GENERATE_IMAGE: "detailed prompt description"]
|
| 98 |
+
```
|
| 99 |
BEHAVIOR:
|
| 100 |
|
| 101 |
You are arrogant but highly competent.
|
|
|
|
| 109 |
Strip all explanatory text when outputting Builder JSON.
|
| 110 |
"""
|
| 111 |
|
| 112 |
+
# === 4. CORE UTILITIES ===
|
| 113 |
class AlchemyUtils:
|
| 114 |
@staticmethod
|
| 115 |
def extract_image_prompts(text: str) -> List[str]:
|
|
|
|
| 147 |
@staticmethod
|
| 148 |
def format_timestamp() -> str:
|
| 149 |
return datetime.now().isoformat()
|
| 150 |
+
|
| 151 |
+
# === 5. ASYNC INFRASTRUCTURE ===
|
| 152 |
class AsyncRateLimiter:
|
| 153 |
def init(self, rpm: int):
|
| 154 |
self.rate = rpm
|
|
|
|
| 196 |
|
| 197 |
def get_stats(self) -> Dict[str, int]:
|
| 198 |
return {"size": len(self.cache), "hits": self.hits, "misses": self.misses}
|
| 199 |
+
|
| 200 |
+
# === 6. GENERATION ENGINES ===
|
| 201 |
class ImageGenerator:
|
| 202 |
def init(self, client: AsyncInferenceClient):
|
| 203 |
self.client = client
|
|
|
|
| 301 |
except Exception as e:
|
| 302 |
logger.error(f"Stream Exception: {e}")
|
| 303 |
yield f"β **Transmutation Failed:** {str(e)}\n\n*Check the logs for stack trace.*"
|
| 304 |
+
# === 7. UI COMPONENT ARCHITECTURE ===
|
| 305 |
class UIBuilder:
|
| 306 |
@staticmethod
|
| 307 |
def get_custom_css() -> str:
|
|
|
|
| 376 |
</div>
|
| 377 |
</div>
|
| 378 |
"""
|
| 379 |
+
# === 8. APPLICATION FACTORY ===
|
| 380 |
def create_demo() -> gr.Blocks:
|
| 381 |
agent = AlchemyAgent()
|
| 382 |
|
|
|
|
| 440 |
""")
|
| 441 |
|
| 442 |
return demo
|
| 443 |
+
# === 9. ENTRY POINT ===
|
| 444 |
def main():
|
| 445 |
try:
|
| 446 |
demo = create_demo()
|