Update app.py
Browse files
app.py
CHANGED
|
@@ -5,6 +5,7 @@ import gradio as gr
|
|
| 5 |
import requests
|
| 6 |
import pandas as pd
|
| 7 |
from smolagents import CodeAgent, DuckDuckGoSearchTool, tool
|
|
|
|
| 8 |
|
| 9 |
logging.basicConfig(level=logging.INFO, format="%(asctime)s [%(levelname)s] %(message)s")
|
| 10 |
logger = logging.getLogger(__name__)
|
|
@@ -97,7 +98,8 @@ Formatting Rules for FINAL ANSWER:
|
|
| 97 |
Let's begin!
|
| 98 |
"""
|
| 99 |
|
| 100 |
-
|
|
|
|
| 101 |
def __init__(self, model_id="openai-large", max_tokens=8196, seed=42):
|
| 102 |
self.model_id = model_id
|
| 103 |
self.max_tokens = max_tokens
|
|
@@ -120,32 +122,15 @@ class PollinationsModel:
|
|
| 120 |
}
|
| 121 |
response = requests.post(self.api_url, json=payload, timeout=120)
|
| 122 |
response.raise_for_status()
|
| 123 |
-
|
| 124 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 125 |
except Exception as e:
|
| 126 |
logger.exception(f"PollinationsModel generate failed: {e}")
|
| 127 |
return f"Error generating response: {str(e)}"
|
| 128 |
-
|
| 129 |
-
def __call__(self, messages=None, **kwargs):
|
| 130 |
-
"""Make the model callable as required by smolagents CodeAgent."""
|
| 131 |
-
prompt = ""
|
| 132 |
-
if messages and isinstance(messages, list) and len(messages) > 0:
|
| 133 |
-
# Get content from the last message
|
| 134 |
-
if hasattr(messages[-1], 'content'):
|
| 135 |
-
prompt = messages[-1].content
|
| 136 |
-
elif isinstance(messages[-1], dict) and 'content' in messages[-1]:
|
| 137 |
-
prompt = messages[-1]['content']
|
| 138 |
-
|
| 139 |
-
response_text = self.generate(prompt)
|
| 140 |
-
|
| 141 |
-
# Create a response object with the content attribute
|
| 142 |
-
class ChatMessage:
|
| 143 |
-
def __init__(self, content):
|
| 144 |
-
self.content = content
|
| 145 |
-
|
| 146 |
-
return ChatMessage(response_text)
|
| 147 |
-
|
| 148 |
-
|
| 149 |
|
| 150 |
logger.info(f"Initializing Pollinations LLM connection: {MODEL_ID}")
|
| 151 |
try:
|
|
@@ -249,4 +234,4 @@ logger.info("Gradio interface setup complete.")
|
|
| 249 |
if __name__ == "__main__":
|
| 250 |
logger.info("Launching Gradio application...")
|
| 251 |
demo.launch(debug=True, share=False)
|
| 252 |
-
logger.info("Gradio application launched.")
|
|
|
|
| 5 |
import requests
|
| 6 |
import pandas as pd
|
| 7 |
from smolagents import CodeAgent, DuckDuckGoSearchTool, tool
|
| 8 |
+
from smolagents.models import BaseModel
|
| 9 |
|
| 10 |
logging.basicConfig(level=logging.INFO, format="%(asctime)s [%(levelname)s] %(message)s")
|
| 11 |
logger = logging.getLogger(__name__)
|
|
|
|
| 98 |
Let's begin!
|
| 99 |
"""
|
| 100 |
|
| 101 |
+
# Benutzerdefiniertes Modell für Pollinations API
|
| 102 |
+
class PollinationsModel(BaseModel):
|
| 103 |
def __init__(self, model_id="openai-large", max_tokens=8196, seed=42):
|
| 104 |
self.model_id = model_id
|
| 105 |
self.max_tokens = max_tokens
|
|
|
|
| 122 |
}
|
| 123 |
response = requests.post(self.api_url, json=payload, timeout=120)
|
| 124 |
response.raise_for_status()
|
| 125 |
+
result = response.json()
|
| 126 |
+
if "content" in result:
|
| 127 |
+
return result["content"]
|
| 128 |
+
else:
|
| 129 |
+
logger.error(f"Unexpected response structure: {result}")
|
| 130 |
+
return "Error: Unexpected API response format"
|
| 131 |
except Exception as e:
|
| 132 |
logger.exception(f"PollinationsModel generate failed: {e}")
|
| 133 |
return f"Error generating response: {str(e)}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 134 |
|
| 135 |
logger.info(f"Initializing Pollinations LLM connection: {MODEL_ID}")
|
| 136 |
try:
|
|
|
|
| 234 |
if __name__ == "__main__":
|
| 235 |
logger.info("Launching Gradio application...")
|
| 236 |
demo.launch(debug=True, share=False)
|
| 237 |
+
logger.info("Gradio application launched.")
|