Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,69 +1,45 @@
|
|
| 1 |
-
from smolagents import CodeAgent, HfApiModel, load_tool, tool
|
| 2 |
import datetime
|
|
|
|
| 3 |
import pytz
|
| 4 |
import yaml
|
| 5 |
-
from transformers import pipeline
|
| 6 |
from tools.final_answer import FinalAnswerTool
|
| 7 |
from Gradio_UI import GradioUI
|
| 8 |
|
| 9 |
-
#
|
| 10 |
-
asr_pipeline = pipeline("automatic-speech-recognition", model="facebook/wav2vec2-large-960h")
|
| 11 |
-
|
| 12 |
-
# Tool: Convert time between time zones
|
| 13 |
@tool
|
| 14 |
-
def
|
| 15 |
-
"""
|
| 16 |
Args:
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
|
|
|
|
|
|
| 20 |
"""
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
return f"Time in {to_tz}: {converted_time}"
|
| 28 |
-
except Exception as e:
|
| 29 |
-
return f"Error converting time: {str(e)}"
|
| 30 |
-
|
| 31 |
|
| 32 |
-
#
|
| 33 |
@tool
|
| 34 |
-
def
|
| 35 |
-
"""
|
| 36 |
Args:
|
| 37 |
-
|
| 38 |
"""
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
return f"Alert assigned to: {department}"
|
| 49 |
-
return "Alert could not be assigned automatically. Please check manually."
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
# Tool: Transcribe audio and generate a timeline using Hugging Face ASR
|
| 53 |
-
@tool
|
| 54 |
-
def transcribe_audio(audio_path: str) -> str:
|
| 55 |
-
"""Transcribe audio and log events with timestamps.
|
| 56 |
-
Args:
|
| 57 |
-
audio_path: Path to the audio file.
|
| 58 |
-
"""
|
| 59 |
-
try:
|
| 60 |
-
result = asr_pipeline(audio_path)
|
| 61 |
-
transcript = result["text"]
|
| 62 |
-
timestamped_events = [f"{datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')} - {line}" for line in transcript.split('.')]
|
| 63 |
-
return "\n".join(timestamped_events)
|
| 64 |
-
except Exception as e:
|
| 65 |
-
return f"Error transcribing audio: {str(e)}"
|
| 66 |
-
|
| 67 |
|
| 68 |
final_answer = FinalAnswerTool()
|
| 69 |
|
|
@@ -74,19 +50,22 @@ model = HfApiModel(
|
|
| 74 |
custom_role_conversions=None,
|
| 75 |
)
|
| 76 |
|
|
|
|
|
|
|
| 77 |
with open("prompts.yaml", 'r') as stream:
|
| 78 |
prompt_templates = yaml.safe_load(stream)
|
| 79 |
-
|
| 80 |
agent = CodeAgent(
|
| 81 |
model=model,
|
| 82 |
-
tools=[final_answer,
|
| 83 |
max_steps=6,
|
| 84 |
verbosity_level=1,
|
| 85 |
grammar=None,
|
| 86 |
planning_interval=None,
|
| 87 |
-
name=
|
| 88 |
-
description=
|
| 89 |
prompt_templates=prompt_templates
|
| 90 |
)
|
| 91 |
|
| 92 |
GradioUI(agent).launch()
|
|
|
|
|
|
| 1 |
+
from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel, load_tool, tool
|
| 2 |
import datetime
|
| 3 |
+
import requests
|
| 4 |
import pytz
|
| 5 |
import yaml
|
|
|
|
| 6 |
from tools.final_answer import FinalAnswerTool
|
| 7 |
from Gradio_UI import GradioUI
|
| 8 |
|
| 9 |
+
# Herramienta para clasificar alertas P1, P2, P3 basado en criterios de la tabla
|
|
|
|
|
|
|
|
|
|
| 10 |
@tool
|
| 11 |
+
def classify_alert(service_criticity: str, disruption: str, affectation_time: str, magnitude: str, business_workaround: str) -> str:
|
| 12 |
+
"""Clasifica una alerta en P1, P2 o P3 según los criterios especificados.
|
| 13 |
Args:
|
| 14 |
+
service_criticity: 'High' o 'Low'
|
| 15 |
+
disruption: 'Full', 'Degraded', 'None'
|
| 16 |
+
affectation_time: 'Up 15 mins' o 'Less 15 mins'
|
| 17 |
+
magnitude: 'High', 'Low', 'None'
|
| 18 |
+
business_workaround: 'Yes' o 'No'
|
| 19 |
"""
|
| 20 |
+
if service_criticity == "High" and disruption in ["Full", "Degraded"] and magnitude == "High" and business_workaround == "No":
|
| 21 |
+
return "P1 - Crítico"
|
| 22 |
+
elif service_criticity == "High" and (disruption in ["Full", "Degraded"] or affectation_time == "Up 15 mins"):
|
| 23 |
+
return "P2 - Importante"
|
| 24 |
+
else:
|
| 25 |
+
return "P3 - Menor"
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
|
| 27 |
+
# Herramienta para generar resúmenes de reportes de infraestructura
|
| 28 |
@tool
|
| 29 |
+
def summarize_report(report_text: str) -> str:
|
| 30 |
+
"""Genera un resumen de un reporte sobre la infraestructura de la plataforma.
|
| 31 |
Args:
|
| 32 |
+
report_text: Texto del reporte.
|
| 33 |
"""
|
| 34 |
+
api_url = "https://api-inference.huggingface.co/models/facebook/bart-large-cnn"
|
| 35 |
+
headers = {"Authorization": "Bearer YOUR_HF_API_KEY"}
|
| 36 |
+
payload = {"inputs": report_text}
|
| 37 |
+
|
| 38 |
+
response = requests.post(api_url, headers=headers, json=payload)
|
| 39 |
+
if response.status_code == 200:
|
| 40 |
+
return response.json()[0]['summary_text']
|
| 41 |
+
else:
|
| 42 |
+
return "Error al generar el resumen."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
|
| 44 |
final_answer = FinalAnswerTool()
|
| 45 |
|
|
|
|
| 50 |
custom_role_conversions=None,
|
| 51 |
)
|
| 52 |
|
| 53 |
+
image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
|
| 54 |
+
|
| 55 |
with open("prompts.yaml", 'r') as stream:
|
| 56 |
prompt_templates = yaml.safe_load(stream)
|
| 57 |
+
|
| 58 |
agent = CodeAgent(
|
| 59 |
model=model,
|
| 60 |
+
tools=[final_answer, classify_alert, summarize_report],
|
| 61 |
max_steps=6,
|
| 62 |
verbosity_level=1,
|
| 63 |
grammar=None,
|
| 64 |
planning_interval=None,
|
| 65 |
+
name=None,
|
| 66 |
+
description=None,
|
| 67 |
prompt_templates=prompt_templates
|
| 68 |
)
|
| 69 |
|
| 70 |
GradioUI(agent).launch()
|
| 71 |
+
|