Update app.py
Browse files
app.py
CHANGED
|
@@ -2,16 +2,29 @@ from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel, tool
|
|
| 2 |
import datetime
|
| 3 |
import pytz
|
| 4 |
import yaml
|
| 5 |
-
import
|
|
|
|
| 6 |
from tools.final_answer import FinalAnswerTool
|
| 7 |
from Gradio_UI import GradioUI
|
| 8 |
|
| 9 |
-
# Dynamically load the predict function from
|
| 10 |
-
#
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
@tool
|
| 17 |
def my_custom_tool(arg1: str, arg2: int) -> str:
|
|
@@ -63,13 +76,13 @@ def probe_story_preferences(likes: str, dislikes: str, favorite_theme: str) -> s
|
|
| 63 |
@tool
|
| 64 |
def generate_studio_ghibli_image(prompt: str) -> str:
|
| 65 |
"""
|
| 66 |
-
Generates a Studio Ghibli style image using the predict function from
|
| 67 |
|
| 68 |
Args:
|
| 69 |
prompt: The text prompt describing the desired image.
|
| 70 |
|
| 71 |
Returns:
|
| 72 |
-
The
|
| 73 |
"""
|
| 74 |
try:
|
| 75 |
result = predict(prompt)
|
|
@@ -133,14 +146,13 @@ agent = CodeAgent(
|
|
| 133 |
prompt_templates=prompt_templates
|
| 134 |
)
|
| 135 |
|
| 136 |
-
#
|
| 137 |
initial_opener = (
|
| 138 |
"Welcome to Ghibili Interactive Tale!\n\n"
|
| 139 |
-
"I
|
| 140 |
-
"I
|
| 141 |
-
"
|
| 142 |
-
"
|
| 143 |
-
"Let's embark on this enchanting journey together!"
|
| 144 |
)
|
| 145 |
agent.conversation = [{"role": "assistant", "content": initial_opener}]
|
| 146 |
|
|
|
|
| 2 |
import datetime
|
| 3 |
import pytz
|
| 4 |
import yaml
|
| 5 |
+
import requests
|
| 6 |
+
import sys
|
| 7 |
from tools.final_answer import FinalAnswerTool
|
| 8 |
from Gradio_UI import GradioUI
|
| 9 |
|
| 10 |
+
# --- Dynamically load the predict function from the HF space repository ---
|
| 11 |
+
# Use the raw URL (resolve URL) to fetch app.py from the Studio-Ghibli-LORA-SDXL space.
|
| 12 |
+
app_py_url = "https://huggingface.co/spaces/artificialguybr/Studio-Ghibli-LORA-SDXL/resolve/main/app.py"
|
| 13 |
+
response = requests.get(app_py_url)
|
| 14 |
+
if response.status_code == 200:
|
| 15 |
+
code = response.text
|
| 16 |
+
module_namespace = {}
|
| 17 |
+
try:
|
| 18 |
+
exec(code, module_namespace)
|
| 19 |
+
except Exception as e:
|
| 20 |
+
raise Exception(f"Error executing app.py code: {e}")
|
| 21 |
+
predict = module_namespace.get("predict")
|
| 22 |
+
if not predict:
|
| 23 |
+
raise Exception("Predict function not found in app.py")
|
| 24 |
+
else:
|
| 25 |
+
raise Exception("Failed to load app.py from the repository")
|
| 26 |
+
|
| 27 |
+
# --- Define Tools ---
|
| 28 |
|
| 29 |
@tool
|
| 30 |
def my_custom_tool(arg1: str, arg2: int) -> str:
|
|
|
|
| 76 |
@tool
|
| 77 |
def generate_studio_ghibli_image(prompt: str) -> str:
|
| 78 |
"""
|
| 79 |
+
Generates a Studio Ghibli style image using the predict function loaded from app.py.
|
| 80 |
|
| 81 |
Args:
|
| 82 |
prompt: The text prompt describing the desired image.
|
| 83 |
|
| 84 |
Returns:
|
| 85 |
+
The output of the predict function (e.g., an image URL or base64 string).
|
| 86 |
"""
|
| 87 |
try:
|
| 88 |
result = predict(prompt)
|
|
|
|
| 146 |
prompt_templates=prompt_templates
|
| 147 |
)
|
| 148 |
|
| 149 |
+
# Pre-populate the conversation with an opener
|
| 150 |
initial_opener = (
|
| 151 |
"Welcome to Ghibili Interactive Tale!\n\n"
|
| 152 |
+
"I will guide you through a magical adventure inspired by Studio Ghibli. "
|
| 153 |
+
"I'll ask you about your story preferences, generate vivid scenes with beautiful images, and offer interactive options so you can shape your journey.\n\n"
|
| 154 |
+
"To start, please tell me what kind of adventure you're in the mood for (e.g., whimsical fairy tale, mysterious quest, or serene escape). "
|
| 155 |
+
"Let's begin this enchanting journey together!"
|
|
|
|
| 156 |
)
|
| 157 |
agent.conversation = [{"role": "assistant", "content": initial_opener}]
|
| 158 |
|