Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,9 +1,8 @@
|
|
| 1 |
from PIL import Image, ImageDraw, ImageFont
|
| 2 |
import tempfile
|
| 3 |
import gradio as gr
|
| 4 |
-
from smolagents import CodeAgent, InferenceClientModel
|
| 5 |
from smolagents import DuckDuckGoSearchTool, Tool
|
| 6 |
-
from huggingface_hub import InferenceClient
|
| 7 |
from diffusers import DiffusionPipeline
|
| 8 |
import torch
|
| 9 |
|
|
@@ -64,71 +63,10 @@ def generate_prompts_for_object(object_name):
|
|
| 64 |
"future": f"Show a futuristic version of a {object_name}, by predicting advanced features and futuristic design."
|
| 65 |
}
|
| 66 |
|
| 67 |
-
|
| 68 |
-
# Tool wrapper for m-ric/text-to-image
|
| 69 |
-
# =========================================================
|
| 70 |
-
'''
|
| 71 |
-
class WrappedTextToImageTool(Tool):
|
| 72 |
-
name = "text_to_image"
|
| 73 |
-
description = "Generates an image from a text prompt using the m-ric/text-to-image tool."
|
| 74 |
-
inputs = {
|
| 75 |
-
"prompt": {
|
| 76 |
-
"type": "string",
|
| 77 |
-
"description": "Text prompt to generate an image"
|
| 78 |
-
}
|
| 79 |
-
}
|
| 80 |
-
output_type = "image"
|
| 81 |
-
|
| 82 |
-
def __init__(self):
|
| 83 |
-
self.client = InferenceClient("m-ric/text-to-image")
|
| 84 |
-
|
| 85 |
-
def forward(self, prompt):
|
| 86 |
-
return self.client.text_to_image(prompt)
|
| 87 |
-
|
| 88 |
-
'''
|
| 89 |
-
|
| 90 |
-
'''
|
| 91 |
-
class TextToImageTool(Tool):
|
| 92 |
-
description = "This tool creates an image according to a prompt, which is a text description."
|
| 93 |
-
name = "image_generator"
|
| 94 |
-
inputs = {"prompt": {"type": "string", "description": "The image generator prompt. Don't hesitate to add details in the prompt to make the image look better, like 'high-res, photorealistic', etc."}}
|
| 95 |
-
output_type = "image"
|
| 96 |
-
model_sdxl = "black-forest-labs/FLUX.1-schnell"
|
| 97 |
-
client = InferenceClient(model_sdxl, provider="replicate")
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
def forward(self, prompt):
|
| 101 |
-
return self.client.text_to_image(prompt)
|
| 102 |
-
'''
|
| 103 |
-
'''
|
| 104 |
-
class TextToImageTool(Tool):
|
| 105 |
-
description = "This tool creates an image according to a prompt. Add details like 'high-res, photorealistic'."
|
| 106 |
-
name = "image_generator"
|
| 107 |
-
inputs = {
|
| 108 |
-
"prompt": {
|
| 109 |
-
"type": "string",
|
| 110 |
-
"description": "The image generation prompt"
|
| 111 |
-
}
|
| 112 |
-
}
|
| 113 |
-
output_type = "image"
|
| 114 |
-
|
| 115 |
-
def __init__(self):
|
| 116 |
-
super().__init__()
|
| 117 |
-
dtype = torch.bfloat16
|
| 118 |
-
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 119 |
-
print(f"Using device: {device}")
|
| 120 |
-
self.pipe = DiffusionPipeline.from_pretrained(
|
| 121 |
-
"aiyouthalliance/Free-Image-Generation-CC0",
|
| 122 |
-
torch_dtype=dtype
|
| 123 |
-
).to(device)
|
| 124 |
-
|
| 125 |
-
def forward(self, prompt):
|
| 126 |
-
image = self.pipe(prompt).images[0]
|
| 127 |
-
return image
|
| 128 |
-
'''
|
| 129 |
image_generation_tool = Tool.from_space(
|
| 130 |
"KingNish/Realtime-FLUX",
|
| 131 |
-
api_name="/
|
| 132 |
name="image_generator",
|
| 133 |
description="Generate an image from a prompt"
|
| 134 |
)
|
|
@@ -137,21 +75,9 @@ image_generation_tool = Tool.from_space(
|
|
| 137 |
# =========================================================
|
| 138 |
# Tool and Agent Initialization
|
| 139 |
# =========================================================
|
| 140 |
-
|
| 141 |
-
#image_generation_tool = WrappedTextToImageTool()
|
| 142 |
search_tool = DuckDuckGoSearchTool()
|
| 143 |
-
#print('iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii')
|
| 144 |
#llm_engine = InferenceClientModel("Qwen/Qwen2.5-72B-Instruct")
|
| 145 |
-
#llm_engine = TransformersModel(
|
| 146 |
-
# model_id="Qwen/Qwen2.5-72B-Instruct",
|
| 147 |
-
# device="cuda",
|
| 148 |
-
# max_new_tokens=5000,
|
| 149 |
-
#)
|
| 150 |
-
|
| 151 |
-
#from smolagents import LiteLLMModel
|
| 152 |
-
|
| 153 |
-
#llm_engine = LiteLLMModel(model_id="Qwen/Qwen2.5-72B-Instruct", temperature=0.2, max_tokens=5000)
|
| 154 |
-
#llm_engine=InferenceClientModel()
|
| 155 |
|
| 156 |
llm_engine = InferenceClientModel("Qwen/Qwen2.5-Coder-32B-Instruct")
|
| 157 |
agent = CodeAgent(tools=[image_generation_tool, search_tool], model=llm_engine)
|
|
|
|
| 1 |
from PIL import Image, ImageDraw, ImageFont
|
| 2 |
import tempfile
|
| 3 |
import gradio as gr
|
| 4 |
+
from smolagents import CodeAgent, InferenceClientModel
|
| 5 |
from smolagents import DuckDuckGoSearchTool, Tool
|
|
|
|
| 6 |
from diffusers import DiffusionPipeline
|
| 7 |
import torch
|
| 8 |
|
|
|
|
| 63 |
"future": f"Show a futuristic version of a {object_name}, by predicting advanced features and futuristic design."
|
| 64 |
}
|
| 65 |
|
| 66 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
image_generation_tool = Tool.from_space(
|
| 68 |
"KingNish/Realtime-FLUX",
|
| 69 |
+
api_name="/predict", # Optional if there's only one endpoint
|
| 70 |
name="image_generator",
|
| 71 |
description="Generate an image from a prompt"
|
| 72 |
)
|
|
|
|
| 75 |
# =========================================================
|
| 76 |
# Tool and Agent Initialization
|
| 77 |
# =========================================================
|
| 78 |
+
|
|
|
|
| 79 |
search_tool = DuckDuckGoSearchTool()
|
|
|
|
| 80 |
#llm_engine = InferenceClientModel("Qwen/Qwen2.5-72B-Instruct")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 81 |
|
| 82 |
llm_engine = InferenceClientModel("Qwen/Qwen2.5-Coder-32B-Instruct")
|
| 83 |
agent = CodeAgent(tools=[image_generation_tool, search_tool], model=llm_engine)
|