Spaces:
Sleeping
Sleeping
Download LLM_pipeline.py from CyberRohith/Fast_Image_Generator: direct link, hf CLI and curl.
- Browser
- Download file 1.16 kB
-
https://huggingface.co/spaces/CyberRohith/Fast_Image_Generator/resolve/main/LLM_pipeline.py
- Command line
-
hf download hf://spaces/CyberRohith/Fast_Image_Generator/LLM_pipeline.py
-
curl -L -o LLM_pipeline.py https://huggingface.co/spaces/CyberRohith/Fast_Image_Generator/resolve/main/LLM_pipeline.py
1.16 kB
| import os | |
| import requests | |
| from model_loading import GenerationSession | |
| def prompt_enhancer(user_prompt: str) -> str: | |
| try: | |
| response = requests.post( | |
| "http://localhost:11434/api/generate", | |
| json={ | |
| "model": "mistral", | |
| "format": "json", | |
| "prompt": ( | |
| f"[INST] You are an image generation prompt engineer. " | |
| f"Rewrite this prompt to be vivid and detailed, under 60 words. " | |
| f"Return ONLY the rewritten prompt, nothing else.\n\n" | |
| f"Prompt: {user_prompt} [/INST]" | |
| ), | |
| "stream": False | |
| }, | |
| timeout=60 | |
| ) | |
| except requests.exceptions.ConnectionError: | |
| print("Warning: Could not connect to local Ollama.") | |
| return user_prompt | |
| return response.json()["response"].strip() | |
| def smart_generate(user_prompt: str, session: GenerationSession, strength: float = 0.45): | |
| enhanced = prompt_enhancer(user_prompt) | |
| image = session.Generate(enhanced, strength=strength) | |
| return image[0], enhanced | |