Spaces:
Sleeping
Sleeping
Initial commit with full functionality extend app req tools
Browse files
app.py
CHANGED
|
@@ -2,6 +2,7 @@
|
|
| 2 |
from smolagents import CodeAgent, HfApiModel, Tool
|
| 3 |
import logging
|
| 4 |
from Gradio_UI import GradioUI
|
|
|
|
| 5 |
|
| 6 |
# Configure logging
|
| 7 |
logging.basicConfig(
|
|
@@ -16,9 +17,35 @@ class AnalysisTool(Tool):
|
|
| 16 |
name = "web_analyzer"
|
| 17 |
description = "Analyzes web content for summaries, sentiment, and topics"
|
| 18 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
def forward(self, text: str, analysis_type: str) -> str:
|
| 20 |
"""Process the text based on analysis type."""
|
| 21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
|
| 23 |
def create_agent():
|
| 24 |
"""Create and configure the agent."""
|
|
@@ -36,7 +63,7 @@ def create_agent():
|
|
| 36 |
# Create agent with tools
|
| 37 |
return CodeAgent(
|
| 38 |
model=model,
|
| 39 |
-
tools=[analyzer],
|
| 40 |
max_steps=3,
|
| 41 |
verbosity_level=1
|
| 42 |
)
|
|
|
|
| 2 |
from smolagents import CodeAgent, HfApiModel, Tool
|
| 3 |
import logging
|
| 4 |
from Gradio_UI import GradioUI
|
| 5 |
+
from typing import Dict, Any
|
| 6 |
|
| 7 |
# Configure logging
|
| 8 |
logging.basicConfig(
|
|
|
|
| 17 |
name = "web_analyzer"
|
| 18 |
description = "Analyzes web content for summaries, sentiment, and topics"
|
| 19 |
|
| 20 |
+
# Define the required inputs
|
| 21 |
+
inputs: Dict[str, Any] = {
|
| 22 |
+
"text": {
|
| 23 |
+
"type": "string",
|
| 24 |
+
"description": "The text content to analyze"
|
| 25 |
+
},
|
| 26 |
+
"analysis_type": {
|
| 27 |
+
"type": "string",
|
| 28 |
+
"description": "Type of analysis to perform (summarize, sentiment, or topics)"
|
| 29 |
+
}
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
# Define the output type
|
| 33 |
+
output_type = "string"
|
| 34 |
+
|
| 35 |
def forward(self, text: str, analysis_type: str) -> str:
|
| 36 |
"""Process the text based on analysis type."""
|
| 37 |
+
try:
|
| 38 |
+
if analysis_type == "summarize":
|
| 39 |
+
return f"Summary of the text: {text[:500]}..."
|
| 40 |
+
elif analysis_type == "sentiment":
|
| 41 |
+
return f"Sentiment analysis of: {text[:500]}..."
|
| 42 |
+
elif analysis_type == "topics":
|
| 43 |
+
return f"Topics identified in: {text[:500]}..."
|
| 44 |
+
else:
|
| 45 |
+
return f"Unknown analysis type: {analysis_type}"
|
| 46 |
+
except Exception as e:
|
| 47 |
+
logger.error(f"Error in analysis: {e}")
|
| 48 |
+
return f"Error during analysis: {str(e)}"
|
| 49 |
|
| 50 |
def create_agent():
|
| 51 |
"""Create and configure the agent."""
|
|
|
|
| 63 |
# Create agent with tools
|
| 64 |
return CodeAgent(
|
| 65 |
model=model,
|
| 66 |
+
tools=[analyzer],
|
| 67 |
max_steps=3,
|
| 68 |
verbosity_level=1
|
| 69 |
)
|