changes
Browse files
app.py
CHANGED
|
@@ -17,7 +17,7 @@ from smolagents import CodeAgent, DuckDuckGoSearchTool, FinalAnswerTool, Inferen
|
|
| 17 |
# Load environment variables
|
| 18 |
load_dotenv()
|
| 19 |
|
| 20 |
-
# API Configuration
|
| 21 |
MISTRAL_API_KEY = os.getenv("MISTRAL_API_KEY")
|
| 22 |
SAMBANOVA_API_KEY = os.getenv("SAMBANOVA_API_KEY")
|
| 23 |
MODERATOR_MODEL = os.getenv("MODERATOR_MODEL", "mistral")
|
|
@@ -90,13 +90,10 @@ Please provide a thorough analysis based on current, reliable information."""
|
|
| 90 |
|
| 91 |
class VisualConsensusEngine:
|
| 92 |
def __init__(self, moderator_model: str = None, update_callback=None):
|
| 93 |
-
global MISTRAL_API_KEY, SAMBANOVA_API_KEY
|
| 94 |
-
|
| 95 |
self.moderator_model = moderator_model or MODERATOR_MODEL
|
| 96 |
self.search_agent = WebSearchAgent()
|
| 97 |
self.update_callback = update_callback # For real-time updates
|
| 98 |
|
| 99 |
-
# Use global API keys (which may be updated from UI)
|
| 100 |
self.models = {
|
| 101 |
'mistral': {
|
| 102 |
'name': 'Mistral Large',
|
|
@@ -174,7 +171,6 @@ class VisualConsensusEngine:
|
|
| 174 |
return prompt[:100]
|
| 175 |
|
| 176 |
def _call_sambanova(self, model: str, prompt: str) -> Optional[str]:
|
| 177 |
-
global SAMBANOVA_API_KEY
|
| 178 |
if not SAMBANOVA_API_KEY:
|
| 179 |
return None
|
| 180 |
|
|
@@ -210,7 +206,6 @@ class VisualConsensusEngine:
|
|
| 210 |
return None
|
| 211 |
|
| 212 |
def _call_mistral(self, prompt: str) -> Optional[str]:
|
| 213 |
-
global MISTRAL_API_KEY
|
| 214 |
if not MISTRAL_API_KEY:
|
| 215 |
return None
|
| 216 |
|
|
@@ -705,59 +700,6 @@ def log_discussion_event(event_type: str, speaker: str = "", content: str = "",
|
|
| 705 |
**kwargs
|
| 706 |
})
|
| 707 |
|
| 708 |
-
def update_api_keys(mistral_key, sambanova_key):
|
| 709 |
-
"""Update API keys from UI input"""
|
| 710 |
-
global MISTRAL_API_KEY, SAMBANOVA_API_KEY
|
| 711 |
-
|
| 712 |
-
status_messages = []
|
| 713 |
-
|
| 714 |
-
# Update Mistral key if provided, otherwise keep env var
|
| 715 |
-
if mistral_key.strip():
|
| 716 |
-
MISTRAL_API_KEY = mistral_key.strip()
|
| 717 |
-
status_messages.append("✅ Mistral API key updated")
|
| 718 |
-
elif not MISTRAL_API_KEY:
|
| 719 |
-
status_messages.append("❌ No Mistral API key (env or input)")
|
| 720 |
-
else:
|
| 721 |
-
status_messages.append("✅ Using Mistral API key from environment")
|
| 722 |
-
|
| 723 |
-
# Update SambaNova key if provided, otherwise keep env var
|
| 724 |
-
if sambanova_key.strip():
|
| 725 |
-
SAMBANOVA_API_KEY = sambanova_key.strip()
|
| 726 |
-
status_messages.append("✅ SambaNova API key updated")
|
| 727 |
-
elif not SAMBANOVA_API_KEY:
|
| 728 |
-
status_messages.append("❌ No SambaNova API key (env or input)")
|
| 729 |
-
else:
|
| 730 |
-
status_messages.append("✅ Using SambaNova API key from environment")
|
| 731 |
-
|
| 732 |
-
# Check if we have at least one working key
|
| 733 |
-
if not MISTRAL_API_KEY and not SAMBANOVA_API_KEY:
|
| 734 |
-
return "❌ ERROR: No API keys available! Please provide at least one API key."
|
| 735 |
-
|
| 736 |
-
return " | ".join(status_messages)
|
| 737 |
-
|
| 738 |
-
def check_model_status():
|
| 739 |
-
"""Check and display current model availability"""
|
| 740 |
-
global MISTRAL_API_KEY, SAMBANOVA_API_KEY
|
| 741 |
-
|
| 742 |
-
status_info = "## 🔍 Model Availability Status\n\n"
|
| 743 |
-
|
| 744 |
-
models = {
|
| 745 |
-
'Mistral Large': MISTRAL_API_KEY,
|
| 746 |
-
'DeepSeek-R1': SAMBANOVA_API_KEY,
|
| 747 |
-
'Meta-Llama-3.1-8B': SAMBANOVA_API_KEY,
|
| 748 |
-
'QwQ-32B': SAMBANOVA_API_KEY,
|
| 749 |
-
'Web Search Agent': True
|
| 750 |
-
}
|
| 751 |
-
|
| 752 |
-
for model_name, available in models.items():
|
| 753 |
-
if model_name == 'Web Search Agent':
|
| 754 |
-
status = "✅ Available (Built-in)"
|
| 755 |
-
else:
|
| 756 |
-
status = "✅ Available" if available else "❌ Not configured"
|
| 757 |
-
status_info += f"**{model_name}:** {status}\n\n"
|
| 758 |
-
|
| 759 |
-
return status_info
|
| 760 |
-
|
| 761 |
# Create the hybrid interface
|
| 762 |
with gr.Blocks(title="🎭 Consilium: Visual AI Consensus Platform", theme=gr.themes.Soft()) as demo:
|
| 763 |
gr.Markdown("""
|
|
@@ -908,85 +850,38 @@ with gr.Blocks(title="🎭 Consilium: Visual AI Consensus Platform", theme=gr.th
|
|
| 908 |
gr.Timer(2).tick(lambda: json.dumps(current_roundtable_state), outputs=[roundtable])
|
| 909 |
|
| 910 |
with gr.Tab("🔧 Configuration & Setup"):
|
| 911 |
-
|
| 912 |
-
|
| 913 |
-
|
| 914 |
-
|
| 915 |
-
|
| 916 |
-
|
| 917 |
-
|
| 918 |
-
|
| 919 |
-
|
| 920 |
-
|
| 921 |
-
|
| 922 |
-
|
| 923 |
-
label="SambaNova API Key",
|
| 924 |
-
placeholder="Enter your SambaNova API key...",
|
| 925 |
-
type="password",
|
| 926 |
-
info="Required for DeepSeek, Llama, and QwQ models"
|
| 927 |
-
)
|
| 928 |
-
|
| 929 |
-
with gr.Column():
|
| 930 |
-
# Add a button to save/update keys
|
| 931 |
-
save_keys_btn = gr.Button("💾 Save API Keys", variant="secondary")
|
| 932 |
-
keys_status = gr.Textbox(
|
| 933 |
-
label="Keys Status",
|
| 934 |
-
value="No API keys configured - using environment variables if available",
|
| 935 |
-
interactive=False
|
| 936 |
-
)
|
| 937 |
-
|
| 938 |
-
# Connect the save button
|
| 939 |
-
save_keys_btn.click(
|
| 940 |
-
update_api_keys,
|
| 941 |
-
inputs=[mistral_key_input, sambanova_key_input],
|
| 942 |
-
outputs=[keys_status]
|
| 943 |
-
)
|
| 944 |
-
|
| 945 |
-
model_status_display = gr.Markdown(check_model_status())
|
| 946 |
|
| 947 |
-
|
| 948 |
-
refresh_status_btn = gr.Button("🔄 Refresh Model Status")
|
| 949 |
-
refresh_status_btn.click(
|
| 950 |
-
check_model_status,
|
| 951 |
-
outputs=[model_status_display]
|
| 952 |
-
)
|
| 953 |
|
| 954 |
gr.Markdown("""
|
| 955 |
## 🛠️ Setup Instructions
|
| 956 |
|
| 957 |
-
###
|
| 958 |
-
1. **Enter API keys above** (they'll be used for this session)
|
| 959 |
-
2. **Click "Save API Keys"**
|
| 960 |
-
3. **Start a discussion!**
|
| 961 |
-
|
| 962 |
-
### 🔑 Get API Keys:
|
| 963 |
-
- **Mistral:** [console.mistral.ai](https://console.mistral.ai)
|
| 964 |
-
- **SambaNova:** [cloud.sambanova.ai](https://cloud.sambanova.ai)
|
| 965 |
-
|
| 966 |
-
### 🌐 Alternative: Environment Variables
|
| 967 |
```bash
|
| 968 |
-
|
| 969 |
-
|
| 970 |
-
|
| 971 |
```
|
| 972 |
|
| 973 |
### 🦙 Sambanova Integration
|
| 974 |
-
The platform includes **3 Sambanova models**:
|
| 975 |
- **DeepSeek-R1**: Advanced reasoning model
|
| 976 |
- **Meta-Llama-3.1-8B**: Fast, efficient discussions
|
| 977 |
- **QwQ-32B**: Large-scale consensus analysis
|
| 978 |
|
| 979 |
-
|
| 980 |
-
Built-in agent using **smolagents** with:
|
| 981 |
-
- **DuckDuckGoSearchTool**: Web searches
|
| 982 |
-
- **VisitWebpageTool**: Deep content analysis
|
| 983 |
-
- **WikipediaTool**: Comprehensive research
|
| 984 |
-
- **TinyLlama**: Fast inference for search synthesis
|
| 985 |
-
|
| 986 |
-
### 📋 Dependencies
|
| 987 |
-
```bash
|
| 988 |
-
pip install gradio requests python-dotenv smolagents gradio-consilium-roundtable wikipedia openai
|
| 989 |
-
```
|
| 990 |
|
| 991 |
### 🔗 MCP Integration
|
| 992 |
Add to your Claude Desktop config:
|
|
@@ -1000,6 +895,20 @@ with gr.Blocks(title="🎭 Consilium: Visual AI Consensus Platform", theme=gr.th
|
|
| 1000 |
}
|
| 1001 |
}
|
| 1002 |
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1003 |
""")
|
| 1004 |
|
| 1005 |
with gr.Tab("📚 Usage Examples"):
|
|
@@ -1035,32 +944,6 @@ with gr.Blocks(title="🎭 Consilium: Visual AI Consensus Platform", theme=gr.th
|
|
| 1035 |
- 🎯 **Center consensus** = Final decision reached
|
| 1036 |
|
| 1037 |
**The roundtable updates in real-time as the discussion progresses!**
|
| 1038 |
-
|
| 1039 |
-
## 🎮 Role Assignments Explained
|
| 1040 |
-
|
| 1041 |
-
### 🎭 Balanced (Recommended)
|
| 1042 |
-
- **Devil's Advocate**: Challenges assumptions
|
| 1043 |
-
- **Fact Checker**: Verifies claims and accuracy
|
| 1044 |
-
- **Synthesizer**: Finds common ground
|
| 1045 |
-
- **Standard**: Provides balanced analysis
|
| 1046 |
-
|
| 1047 |
-
### 🎓 Specialized
|
| 1048 |
-
- **Domain Expert**: Technical expertise
|
| 1049 |
-
- **Fact Checker**: Accuracy verification
|
| 1050 |
-
- **Creative Thinker**: Innovative solutions
|
| 1051 |
-
- **Synthesizer**: Bridge building
|
| 1052 |
-
|
| 1053 |
-
### ⚔️ Adversarial
|
| 1054 |
-
- **Double Devil's Advocate**: Maximum challenge
|
| 1055 |
-
- **Standard**: Balanced counter-perspective
|
| 1056 |
-
|
| 1057 |
-
## 🗳️ Decision Protocols
|
| 1058 |
-
|
| 1059 |
-
- **Consensus**: Seek agreement among all participants
|
| 1060 |
-
- **Majority Voting**: Most popular position wins
|
| 1061 |
-
- **Weighted Voting**: Higher confidence scores matter more
|
| 1062 |
-
- **Ranked Choice**: Preference-based selection
|
| 1063 |
-
- **Unanimity**: All must agree completely
|
| 1064 |
""")
|
| 1065 |
|
| 1066 |
# Launch configuration
|
|
|
|
| 17 |
# Load environment variables
|
| 18 |
load_dotenv()
|
| 19 |
|
| 20 |
+
# API Configuration
|
| 21 |
MISTRAL_API_KEY = os.getenv("MISTRAL_API_KEY")
|
| 22 |
SAMBANOVA_API_KEY = os.getenv("SAMBANOVA_API_KEY")
|
| 23 |
MODERATOR_MODEL = os.getenv("MODERATOR_MODEL", "mistral")
|
|
|
|
| 90 |
|
| 91 |
class VisualConsensusEngine:
|
| 92 |
def __init__(self, moderator_model: str = None, update_callback=None):
|
|
|
|
|
|
|
| 93 |
self.moderator_model = moderator_model or MODERATOR_MODEL
|
| 94 |
self.search_agent = WebSearchAgent()
|
| 95 |
self.update_callback = update_callback # For real-time updates
|
| 96 |
|
|
|
|
| 97 |
self.models = {
|
| 98 |
'mistral': {
|
| 99 |
'name': 'Mistral Large',
|
|
|
|
| 171 |
return prompt[:100]
|
| 172 |
|
| 173 |
def _call_sambanova(self, model: str, prompt: str) -> Optional[str]:
|
|
|
|
| 174 |
if not SAMBANOVA_API_KEY:
|
| 175 |
return None
|
| 176 |
|
|
|
|
| 206 |
return None
|
| 207 |
|
| 208 |
def _call_mistral(self, prompt: str) -> Optional[str]:
|
|
|
|
| 209 |
if not MISTRAL_API_KEY:
|
| 210 |
return None
|
| 211 |
|
|
|
|
| 700 |
**kwargs
|
| 701 |
})
|
| 702 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 703 |
# Create the hybrid interface
|
| 704 |
with gr.Blocks(title="🎭 Consilium: Visual AI Consensus Platform", theme=gr.themes.Soft()) as demo:
|
| 705 |
gr.Markdown("""
|
|
|
|
| 850 |
gr.Timer(2).tick(lambda: json.dumps(current_roundtable_state), outputs=[roundtable])
|
| 851 |
|
| 852 |
with gr.Tab("🔧 Configuration & Setup"):
|
| 853 |
+
def check_model_status():
|
| 854 |
+
engine = VisualConsensusEngine()
|
| 855 |
+
status_info = "## 🔍 Model Availability Status\n\n"
|
| 856 |
+
|
| 857 |
+
for model_id, model_info in engine.models.items():
|
| 858 |
+
if model_id == 'search':
|
| 859 |
+
status = "✅ Available (Built-in)"
|
| 860 |
+
else:
|
| 861 |
+
status = "✅ Available" if model_info['available'] else "❌ Not configured"
|
| 862 |
+
status_info += f"**{model_info['name']}:** {status}\n\n"
|
| 863 |
+
|
| 864 |
+
return status_info
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 865 |
|
| 866 |
+
gr.Markdown(check_model_status())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 867 |
|
| 868 |
gr.Markdown("""
|
| 869 |
## 🛠️ Setup Instructions
|
| 870 |
|
| 871 |
+
### Environment Variables Setup:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 872 |
```bash
|
| 873 |
+
MISTRAL_API_KEY=...
|
| 874 |
+
SAMBANOVA_API_KEY=...
|
| 875 |
+
MODERATOR_MODEL=mistral
|
| 876 |
```
|
| 877 |
|
| 878 |
### 🦙 Sambanova Integration
|
| 879 |
+
The platform now includes **3 Sambanova models**:
|
| 880 |
- **DeepSeek-R1**: Advanced reasoning model
|
| 881 |
- **Meta-Llama-3.1-8B**: Fast, efficient discussions
|
| 882 |
- **QwQ-32B**: Large-scale consensus analysis
|
| 883 |
|
| 884 |
+
All using Sambanova's ultra-fast inference infrastructure!
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 885 |
|
| 886 |
### 🔗 MCP Integration
|
| 887 |
Add to your Claude Desktop config:
|
|
|
|
| 895 |
}
|
| 896 |
}
|
| 897 |
```
|
| 898 |
+
|
| 899 |
+
### 📋 Dependencies
|
| 900 |
+
```bash
|
| 901 |
+
pip install gradio requests python-dotenv smolagents gradio-consilium-roundtable
|
| 902 |
+
```
|
| 903 |
+
|
| 904 |
+
### 🤖 Search Agent Configuration
|
| 905 |
+
The Web Search Agent uses **smolagents** with:
|
| 906 |
+
- **DuckDuckGoSearchTool**: Initial web searches
|
| 907 |
+
- **VisitWebpageTool**: Deep dive into relevant pages
|
| 908 |
+
- **FinalAnswerTool**: Synthesized comprehensive answers
|
| 909 |
+
- **InferenceClientModel**: Powered by Hugging Face Inference API
|
| 910 |
+
|
| 911 |
+
For optimal search results, ensure you have a stable internet connection.
|
| 912 |
""")
|
| 913 |
|
| 914 |
with gr.Tab("📚 Usage Examples"):
|
|
|
|
| 944 |
- 🎯 **Center consensus** = Final decision reached
|
| 945 |
|
| 946 |
**The roundtable updates in real-time as the discussion progresses!**
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 947 |
""")
|
| 948 |
|
| 949 |
# Launch configuration
|