hermes-toolkit / app.py
cntalk's picture
Hermès Toolkit Space v1.0
d3a1e32 verified
"""
Hermès AI Toolkit - Hugging Face Space
Advanced AI tools for the Hermès Agent system
"""
import gradio as gr
import json
from typing import List, Dict, Any
# Tool definitions for Hermès agent integration
TOOLS = {
"text_generation": {
"name": "Text Generation",
"description": "Generate text using HF Inference API",
"icon": "✍️",
"endpoint": "text-generation"
},
"summarization": {
"name": "Summarization",
"description": "Summarize long text into concise summaries",
"icon": "📝",
"endpoint": "summarization"
},
"translation": {
"name": "Translation",
"description": "Translate text between languages",
"icon": "🌐",
"endpoint": "translation"
},
"question_answering": {
"name": "Question Answering",
"description": "Answer questions based on given context",
"icon": "❓",
"endpoint": "question-answering"
},
"sentiment_analysis": {
"name": "Sentiment Analysis",
"description": "Analyze emotional tone of text",
"icon": "💭",
"endpoint": "sentiment-analysis"
},
"code_generation": {
"name": "Code Generation",
"description": "Generate code from natural language",
"icon": "💻",
"endpoint": "code-generation"
},
"image_classification": {
"name": "Image Classification",
"description": "Classify images into categories",
"icon": "🖼️",
"endpoint": "image-classification"
},
"feature_extraction": {
"name": "Feature Extraction",
"description": "Extract embeddings/features from text",
"icon": "🔍",
"endpoint": "feature-extraction"
}
}
MODELS = {
"text-generation": [
"meta-llama/Llama-3.2-1B-Instruct",
"meta-llama/Llama-3.2-3B-Instruct",
"mistralai/Mistral-7B-Instruct-v0.2",
"microsoft/Phi-3-mini-128k-instruct",
"Qwen/Qwen2.5-7B-Instruct",
"deepseek-ai/DeepSeek-Coder-V2-Lite-Instruct"
],
"summarization": [
"facebook/bart-large-cnn",
"google/pegasus-xsum",
"t5-base"
],
"translation": [
"facebook/mbart-large-50-many-to-many-mmt",
"Helsinki-NLP/opus-mt-zh-en",
"Helsinki-NLP/opus-mt-en-zh"
],
"question-answering": [
"deepset/roberta-base-squad2",
"distilbert-base-cased-distilled-squad"
],
"sentiment-analysis": [
"distilbert-base-uncased-finetuned-sst-2-english",
"nlptown/bert-base-multilingual-uncased-sentiment"
],
"code-generation": [
"deepseek-ai/DeepSeek-Coder-V2-Lite-Instruct",
"mistralai/CodeInstruct-7B"
]
}
def get_tool_card(tool_id: str) -> str:
"""Generate tool card HTML"""
tool = TOOLS.get(tool_id, {})
models = MODELS.get(tool.get("endpoint", ""), [])
models_html = "<br>".join([f"• `{m}`" for m in models[:3]])
if len(models) > 3:
models_html += f"<br>... and {len(models)-3} more"
return f"""
<div style='background: #1a1a2e; padding: 15px; border-radius: 10px; margin: 10px 0;'>
<h3>{tool.get('icon', '🔧')} {tool.get('name', tool_id)}</h3>
<p style='color: #888;'>{tool.get('description', '')}</p>
<details>
<summary style='color: #4ecdc4; cursor: pointer;'>Available Models ({len(models)})</summary>
<div style='margin-top: 10px; color: #aaa;'>{models_html}</div>
</details>
</div>
"""
def build_tools_gallery():
"""Build tools gallery view"""
tools_html = ""
for tool_id in TOOLS:
tools_html += get_tool_card(tool_id)
return tools_html
def build_hero():
"""Build hero section"""
return """# 🤖 Hermès AI Toolkit
Welcome to the Hermès AI Toolkit powered by Hugging Face Inference API.
## What is Hermès?
Hermès is an autonomous AI Agent that can:
- 🔍 Search and research topics
- 💻 Write and debug code
- 📊 Analyze data and generate insights
- 🌐 Translate between languages
- 📝 Summarize documents
- 💡 Answer questions intelligently
## Available Tools
Select a tool from the tabs below to get started.
## Integration
This Space is part of the [cntalk/hermes-agent-resources](https://huggingface.co/collections/cntalk/hermes-agent-resources-69f9c5b62fb70b0bbb6ae0b1) collection.
"""
# Build the interface
with gr.Blocks(
title="Hermès AI Toolkit",
theme=gr.themes.Soft(
primary_hue="teal",
secondary_hue="purple",
neutral_hue="gray",
font=[gr.themes.GoogleFont("Inter")]
)
) as demo:
gr.Markdown(build_hero())
with gr.Tabs():
with gr.TabItem("🛠️ All Tools"):
gr.HTML(build_tools_gallery())
with gr.TabItem("✍️ Text Generation"):
with gr.Row():
with gr.Column():
model_select = gr.Dropdown(
choices=MODELS["text-generation"],
value=MODELS["text-generation"][0],
label="Model"
)
prompt_input = gr.Textbox(
label="Prompt",
placeholder="Enter your prompt here...",
lines=4
)
max_tokens = gr.Slider(32, 4096, value=512, label="Max New Tokens")
temperature = gr.Slider(0.1, 2.0, value=0.7, label="Temperature")
generate_btn = gr.Button("Generate", variant="primary")
with gr.Column():
output = gr.Textbox(label="Output", lines=10)
generate_btn.click(
fn=lambda: "Feature requires HF Inference API client",
inputs=[],
outputs=output
)
with gr.TabItem("📝 Summarization"):
with gr.Row():
with gr.Column():
summ_model = gr.Dropdown(
choices=MODELS["summarization"],
value=MODELS["summarization"][0],
label="Model"
)
summ_input = gr.Textbox(
label="Input Text",
placeholder="Paste text to summarize...",
lines=6
)
summ_btn = gr.Button("Summarize", variant="primary")
with gr.Column():
summ_output = gr.Textbox(label="Summary", lines=6)
summ_btn.click(
fn=lambda: "Feature requires HF Inference API client",
inputs=[],
outputs=summ_output
)
with gr.TabItem("🌐 Translation"):
gr.Markdown("Translation tools using Helsinki-NLP and mBART models")
gr.Examples(
examples=[["Hello, how are you?", "en", "zh"]],
inputs=[],
label="Example translations"
)
with gr.TabItem("❓ QA"):
gr.Markdown("Question Answering using RoBERTa-based models")
with gr.TabItem("💭 Sentiment"):
gr.Markdown("Sentiment Analysis with DistilBERT")
with gr.TabItem("💻 Code"):
gr.Markdown("Code generation powered by DeepSeek Coder")
gr.Markdown("""
---
### 🔗 Hermès Resources
| Resource | Link |
|---------|------|
| Collection | [hermes-agent-resources](https://huggingface.co/collections/cntalk/hermes-agent-resources-69f9c5b62fb70b0bbb6ae0b1) |
| AI Toolkit Space | [hello-hermes](https://huggingface.co/spaces/cntalk/hello-hermes) |
| Examples Dataset | [hermes-examples](https://huggingface.co/datasets/cntalk/hermes-examples) |
| Agent Prompts | [agent-prompts](https://huggingface.co/datasets/cntalk/agent-prompts) |
| Skills Dataset | [hermes-skills](https://huggingface.co/datasets/cntalk/hermes-skills) |
Built with ❤️ for the Hermès AI Agent system
""")
demo.launch()