milwright commited on
Commit
8207555
Β·
1 Parent(s): 153cfa4

Limit model selection to three open-source options

Browse files

- Reduced available models to: Gemma 27B, Mixtral 8x7B, and Llama 70B
- Ordered models by size from smallest to largest
- Focuses on providing quality open-source model options only

.DS_Store ADDED
Binary file (6.15 kB). View file
 
CLAUDE.md ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # CLAUDE.md
2
+
3
+ This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4
+
5
+ ## Commands
6
+
7
+ ### Running the Application
8
+ ```bash
9
+ python app.py
10
+ ```
11
+ This starts the Gradio web interface on local port (default 7860).
12
+
13
+ ### Installing Dependencies
14
+ ```bash
15
+ pip install -r requirements.txt
16
+ ```
17
+
18
+ ## Code Architecture
19
+
20
+ This is a single-file Gradio application (`app.py`) that helps users create and deploy chat interfaces on HuggingFace Spaces. The application has two main features:
21
+
22
+ 1. **Spaces Configuration Tool**: Generates complete deployment packages for chat interfaces
23
+ - Uses the `SPACE_TEMPLATE` string (lines 9-81) to generate Python code
24
+ - Creates zip files containing app.py, requirements.txt, and README.md
25
+ - Supports multiple LLM models via OpenRouter API
26
+
27
+ 2. **Chat Support Assistant**: Provides configuration help using Gemma-2-27B
28
+ - Located in the second tab of the interface
29
+ - Uses OpenRouter API with environment variable `OPENROUTER_API_KEY`
30
+
31
+ ### Key Functions
32
+ - `create_readme()`: Generates deployment instructions (lines 99-117)
33
+ - `create_requirements()`: Generates requirements.txt content (lines 119-127)
34
+ - `generate_space_config()`: Main function that creates the deployment package (lines 129-180)
35
+ - `create_support_assistant()`: Creates the chat support interface (lines 396-449)
36
+
37
+ ### Template System
38
+ The app uses string templating to generate Python code. The main template (`SPACE_TEMPLATE`) contains placeholders that are filled with user configuration:
39
+ - `{name}`, `{description}`, `{system_prompt}`, `{model}`
40
+ - `{api_key_var}`, `{temperature}`, `{max_tokens}`, `{examples}`
41
+
42
+ ## Environment Variables
43
+ - `OPENROUTER_API_KEY`: Required for the Chat Support feature to work
44
+
45
+ ## Important Notes
46
+ - This is a HuggingFace Spaces application (see YAML frontmatter in README.md)
47
+ - No test suite or linting configuration exists
48
+ - The generated packages are self-contained chat applications ready for deployment
49
+ - All generated code uses OpenRouter API for LLM access
__pycache__/app.cpython-312.pyc ADDED
Binary file (12.6 kB). View file
 
app.py CHANGED
@@ -82,18 +82,9 @@ if __name__ == "__main__":
82
 
83
  # Available models
84
  MODELS = [
85
- "google/gemma-2-9b-it",
86
- "google/gemma-2-27b-it",
87
- "meta-llama/llama-3.1-8b-instruct",
88
- "meta-llama/llama-3.1-70b-instruct",
89
- "anthropic/claude-3-haiku",
90
- "anthropic/claude-3-sonnet",
91
- "anthropic/claude-3.5-sonnet",
92
- "openai/gpt-3.5-turbo",
93
- "openai/gpt-4o-mini",
94
- "openai/gpt-4o",
95
- "mistralai/mistral-7b-instruct",
96
- "mistralai/mixtral-8x7b-instruct"
97
  ]
98
 
99
  def create_readme(config):
 
82
 
83
  # Available models
84
  MODELS = [
85
+ "google/gemma-2-27b-it",
86
+ "mistralai/mixtral-8x7b-instruct",
87
+ "meta-llama/llama-3.1-70b-instruct"
 
 
 
 
 
 
 
 
 
88
  ]
89
 
90
  def create_readme(config):
local-files/claude.md ADDED
@@ -0,0 +1,108 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # CLAUDE.md
2
+
3
+ This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4
+
5
+ ## Architecture Overview
6
+
7
+ This is a **Chat UI Helper** that generates ready-to-deploy HuggingFace Spaces for educational and research chat interfaces. The project combines a Gradio-based package generator with an AI-powered configuration assistant.
8
+
9
+ ### Core Components
10
+
11
+ 1. **Main Application (`app.py`)**: Two-tab Gradio interface:
12
+ - **Space Generator Tab**: Creates deployable HuggingFace Space packages
13
+ - **Chat UI Helper Tab**: AI assistant for configuration guidance (imported from `chat_helper.py`)
14
+
15
+ 2. **Template System**:
16
+ - `SPACE_TEMPLATE` string contains complete deployable chat interface code
17
+ - Uses Python `.format()` to inject user configurations into template
18
+ - Generates zip packages with `app.py`, `requirements.txt`, `README.md`, and `config.json`
19
+
20
+ 3. **Chat Helper (`chat_helper.py`)**:
21
+ - Modular AI assistant component for configuration guidance
22
+ - Rule-based responses for common educational/research chat UI questions
23
+ - Emphasizes Mixtral-8x7B as cost-effective recommended model
24
+
25
+ ### Key Architecture Patterns
26
+
27
+ - **Template Injection**: Uses `{{}}` for literal braces in generated code, `{}` for template variables
28
+ - **Modular Design**: Chat helper is separate module imported by main app
29
+ - **Configuration-Driven**: All generated spaces use environment-based API key configuration
30
+ - **Educational Focus**: Specialized for academic and research use cases
31
+
32
+ ## Development Commands
33
+
34
+ ### Local Development
35
+ ```bash
36
+ # Install dependencies
37
+ pip install -r requirements.txt
38
+
39
+ # Run the main application
40
+ python app.py
41
+
42
+ # Test a basic assistant template
43
+ python default.py
44
+ ```
45
+
46
+ ### Testing Generated Packages
47
+ ```bash
48
+ # Extract and test a generated zip package
49
+ unzip my_custom_space.zip
50
+ cd extracted_package
51
+ export OPENROUTER_API_KEY="your-key-here"
52
+ python app.py
53
+ ```
54
+
55
+ ### Requirements
56
+ - All generated chat interfaces require OpenRouter API keys
57
+ - Current Gradio version: 5.34.0 (updated from legacy 4.16.0)
58
+ - Template generates Gradio ChatInterface applications
59
+
60
+ ## Template System Details
61
+
62
+ ### SPACE_TEMPLATE Structure
63
+ The template generates complete HuggingFace Spaces with:
64
+ - OpenRouter API integration using configurable environment variables
65
+ - Gradio 5.x compatible ChatInterface implementation
66
+ - Error handling for missing API keys
67
+ - Configurable model, temperature, and token limits
68
+ - Support for custom example prompts
69
+
70
+ ### Configuration Variables
71
+ Standard variables injected into templates:
72
+ - `{name}`: Space title/name
73
+ - `{description}`: Space description
74
+ - `{system_prompt}`: AI behavior instructions
75
+ - `{model}`: OpenRouter model identifier
76
+ - `{api_key_var}`: Environment variable name for API key
77
+ - `{temperature}`: Model temperature setting
78
+ - `{max_tokens}`: Maximum response tokens
79
+ - `{examples}`: JSON array of example prompts
80
+
81
+ ### Template Compatibility
82
+ - Template uses double braces `{{API_KEY}}` for variables that should appear literally in generated code
83
+ - Single braces `{model}` are replaced during template formatting
84
+ - Generated code is compatible with HuggingFace Spaces deployment
85
+
86
+ ## Model Configuration
87
+
88
+ ### Default Model List
89
+ Available models prioritized by use case:
90
+ - **Budget**: `google/gemma-2-9b-it`, `mistralai/mistral-7b-instruct`
91
+ - **Recommended**: `mistralai/mixtral-8x7b-instruct` (balanced cost/performance)
92
+ - **Premium**: `anthropic/claude-3.5-sonnet`, `openai/gpt-4o`
93
+
94
+ ### Chat Helper Integration
95
+ The `chat_helper.py` module provides AI-powered guidance specifically recommending Mixtral-8x7B for most educational and research use cases, with configuration examples and cost considerations.
96
+
97
+ ## File Structure Patterns
98
+
99
+ - `app.py`: Main two-tab application
100
+ - `chat_helper.py`: Modular AI assistant component
101
+ - `default.py`: Basic working assistant template for testing
102
+ - `config.json`: Example configuration file
103
+ - `exp/`: Legacy experimental versions and documentation
104
+ - Generated zip files follow pattern: `{name}_{timestamp}.zip` β†’ `{name}.zip`
105
+
106
+ ## Current State
107
+
108
+ The project has evolved from experimental multi-SDK generator (`exp/` folder) to focused educational/research chat UI helper. Current production stack generates HuggingFace Spaces optimized for academic use cases with built-in configuration guidance.
local-files/zip/cloze_reader_assistant_1750033320.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:84aac5a482cc847c796d50298da89d3964f1e1cd954933aa163142d2741639c1
3
+ size 2769
local-files/zip/my_ai_assistant_assistant_1750031622.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:0e5a395a4f5f7c871689c0b773249ac7ed3d1f484f8b7f3839662623f197186c
3
+ size 2859
local-files/zip/my_ai_assistant_assistant_1750032133.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:70d009797658f4eab0d4cb4e10fb7e5230d6d3ae2d839358cdabccc734ef4c99
3
+ size 2838
local-files/zip/my_ai_assistant_assistant_1750033267.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:6f7871d5ca87f7d4ba97c0f6065a908e02c43a2794fd92fddd61252882d83f15
3
+ size 2761
local-files/zip/my_custom_space.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:425aa4367155cde65095d7c930d2b4295ec5a0e2243badf924f21c21550ebed8
3
+ size 2837
local-files/zip/professor_zach_assistant_1750033356.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:59eee639803656a372b04affbada5007f221c7be9f534544f932b60a3ea5f116
3
+ size 2775
local-files/zip/test_assistant_1750026513.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:8d5b897f2e81fca7bd64207ad86676725ad34005a72e9df3f7d754fffec69d5b
3
+ size 2339
local-files/zip/zip.py ADDED
@@ -0,0 +1,219 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """Test script to validate zip generation functionality"""
3
+
4
+ import json
5
+ import zipfile
6
+ import io
7
+ import os
8
+ from datetime import datetime
9
+
10
+ def create_requirements():
11
+ """Generate requirements.txt"""
12
+ return "gradio==4.16.0\nrequests==2.31.0"
13
+
14
+ def create_readme(config):
15
+ """Generate README with deployment instructions"""
16
+ return f"""# {config['name']}
17
+
18
+ {config['description']}
19
+
20
+ ## πŸš€ Quick Deploy to HuggingFace Spaces
21
+
22
+ ### Step 1: Create the Space
23
+ 1. Go to https://huggingface.co/spaces
24
+ 2. Click "Create new Space"
25
+ 3. Choose a name for your assistant
26
+ 4. Select **Gradio** as the SDK
27
+ 5. Set visibility (Public/Private)
28
+ 6. Click "Create Space"
29
+
30
+ ### Step 2: Upload Files
31
+ 1. In your new Space, click "Files" tab
32
+ 2. Upload these files from the zip:
33
+ - `app.py`
34
+ - `requirements.txt`
35
+ 3. Wait for "Building" to complete
36
+
37
+ ### Step 3: Add API Key
38
+ 1. Go to Settings (βš™οΈ icon)
39
+ 2. Click "Variables and secrets"
40
+ 3. Click "New secret"
41
+ 4. Name: `{config['api_key_var']}`
42
+ 5. Value: Your OpenRouter API key
43
+ 6. Click "Add"
44
+
45
+ ### Step 4: Get Your API Key
46
+ 1. Go to https://openrouter.ai/keys
47
+ 2. Sign up/login if needed
48
+ 3. Click "Create Key"
49
+ 4. Copy the key (starts with `sk-or-`)
50
+
51
+ ### Step 5: Test Your Assistant
52
+ - Go back to "App" tab
53
+ - Your assistant should be running!
54
+ - Try the example prompts or ask a question
55
+
56
+ ## πŸ“ Configuration
57
+
58
+ - **Model**: {config['model']}
59
+ - **Temperature**: {config['temperature']}
60
+ - **Max Tokens**: {config['max_tokens']}
61
+ - **API Key Variable**: {config['api_key_var']}
62
+
63
+ Generated on {datetime.now().strftime('%Y-%m-%d %H:%M:%S')} with HF Assistant Converter
64
+ """
65
+
66
+ # Fixed template based on mvp_simple.py
67
+ ASSISTANT_TEMPLATE = '''import gradio as gr
68
+ import os
69
+ import requests
70
+ import json
71
+
72
+ # Configuration
73
+ ASSISTANT_NAME = "{name}"
74
+ ASSISTANT_DESCRIPTION = "{description}"
75
+ SYSTEM_PROMPT = """{system_prompt}"""
76
+ MODEL = "{model}"
77
+
78
+ # Get API key from environment - customizable variable name
79
+ API_KEY = os.environ.get("{api_key_var}")
80
+
81
+ def generate_response(message, history):
82
+ """Generate response using OpenRouter API"""
83
+
84
+ if not API_KEY:
85
+ return "Please set your {api_key_var} in the Space settings."
86
+
87
+ # Build messages array for the API
88
+ messages = [{{"role": "system", "content": SYSTEM_PROMPT}}]
89
+
90
+ # Add conversation history
91
+ for user_msg, assistant_msg in history:
92
+ messages.append({{"role": "user", "content": user_msg}})
93
+ if assistant_msg:
94
+ messages.append({{"role": "assistant", "content": assistant_msg}})
95
+
96
+ # Add current message
97
+ messages.append({{"role": "user", "content": message}})
98
+
99
+ # Make API request
100
+ try:
101
+ response = requests.post(
102
+ url="https://openrouter.ai/api/v1/chat/completions",
103
+ headers={{
104
+ "Authorization": f"Bearer {{API_KEY}}",
105
+ "Content-Type": "application/json"
106
+ }},
107
+ json={{
108
+ "model": MODEL,
109
+ "messages": messages,
110
+ "temperature": {temperature},
111
+ "max_tokens": {max_tokens}
112
+ }}
113
+ )
114
+
115
+ if response.status_code == 200:
116
+ return response.json()['choices'][0]['message']['content']
117
+ else:
118
+ return f"Error: {{response.status_code}} - {{response.text}}"
119
+
120
+ except Exception as e:
121
+ return f"Error: {{str(e)}}"
122
+
123
+ # Create simple Gradio interface using ChatInterface
124
+ demo = gr.ChatInterface(
125
+ fn=generate_response,
126
+ title=ASSISTANT_NAME,
127
+ description=ASSISTANT_DESCRIPTION,
128
+ examples={examples}
129
+ )
130
+
131
+ if __name__ == "__main__":
132
+ demo.launch(share=True)
133
+ '''
134
+
135
+ def test_zip_generation():
136
+ """Test the zip generation with sample data"""
137
+ print("πŸ§ͺ Testing zip generation...")
138
+
139
+ # Sample configuration
140
+ config = {
141
+ 'name': 'Test Assistant',
142
+ 'description': 'A helpful test assistant',
143
+ 'system_prompt': 'You are a helpful assistant. Provide clear and accurate responses.',
144
+ 'model': 'google/gemma-2-9b-it',
145
+ 'api_key_var': 'OPENROUTER_API_KEY',
146
+ 'temperature': 0.7,
147
+ 'max_tokens': 1024,
148
+ 'examples': json.dumps([
149
+ "Hello! How can you help me?",
150
+ "Tell me something interesting",
151
+ "What can you do?"
152
+ ])
153
+ }
154
+
155
+ print(f"πŸ“‹ Config: {config}")
156
+
157
+ try:
158
+ # Generate files
159
+ print("πŸ”„ Generating app.py content...")
160
+ app_content = ASSISTANT_TEMPLATE.format(**config)
161
+ print("βœ… App content generated")
162
+
163
+ print("πŸ”„ Generating README content...")
164
+ readme_content = create_readme(config)
165
+ print("βœ… README content generated")
166
+
167
+ print("πŸ”„ Generating requirements content...")
168
+ requirements_content = create_requirements()
169
+ print("βœ… Requirements content generated")
170
+
171
+ # Create zip file
172
+ print("πŸ”„ Creating zip file...")
173
+ import time
174
+ timestamp = int(time.time())
175
+ filename = f"test_assistant_{timestamp}.zip"
176
+
177
+ zip_buffer = io.BytesIO()
178
+ with zipfile.ZipFile(zip_buffer, 'w', zipfile.ZIP_DEFLATED) as zip_file:
179
+ zip_file.writestr('app.py', app_content)
180
+ zip_file.writestr('requirements.txt', requirements_content)
181
+ zip_file.writestr('README.md', readme_content)
182
+ zip_file.writestr('config.json', json.dumps(config, indent=2))
183
+
184
+ # Write to file
185
+ zip_buffer.seek(0)
186
+ with open(filename, 'wb') as f:
187
+ f.write(zip_buffer.getvalue())
188
+
189
+ # Verify file
190
+ if os.path.exists(filename):
191
+ file_size = os.path.getsize(filename)
192
+ print(f"βœ… Zip file created: {filename} ({file_size} bytes)")
193
+
194
+ # Test zip contents
195
+ with zipfile.ZipFile(filename, 'r') as zip_file:
196
+ files_in_zip = zip_file.namelist()
197
+ print(f"πŸ“ Files in zip: {files_in_zip}")
198
+
199
+ # Test app.py content
200
+ app_py_content = zip_file.read('app.py').decode('utf-8')
201
+ print(f"πŸ“„ app.py first 100 chars: {app_py_content[:100]}...")
202
+
203
+ return True, filename
204
+ else:
205
+ print("❌ Zip file not created")
206
+ return False, None
207
+
208
+ except Exception as e:
209
+ print(f"❌ Error during zip generation: {str(e)}")
210
+ import traceback
211
+ traceback.print_exc()
212
+ return False, None
213
+
214
+ if __name__ == "__main__":
215
+ success, filename = test_zip_generation()
216
+ if success:
217
+ print(f"πŸŽ‰ Test successful! Generated: {filename}")
218
+ else:
219
+ print("πŸ’₯ Test failed!")