milwright commited on
Commit
9d35415
·
verified ·
1 Parent(s): 4efe09e

Delete local-files

Browse files
local-files/zip/cloze_reader_assistant_1750033320.zip DELETED
@@ -1,3 +0,0 @@
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 DELETED
@@ -1,3 +0,0 @@
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 DELETED
@@ -1,3 +0,0 @@
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 DELETED
@@ -1,3 +0,0 @@
1
- version https://git-lfs.github.com/spec/v1
2
- oid sha256:6f7871d5ca87f7d4ba97c0f6065a908e02c43a2794fd92fddd61252882d83f15
3
- size 2761
 
 
 
 
local-files/zip/my_custom_space.zip DELETED
@@ -1,3 +0,0 @@
1
- version https://git-lfs.github.com/spec/v1
2
- oid sha256:425aa4367155cde65095d7c930d2b4295ec5a0e2243badf924f21c21550ebed8
3
- size 2837
 
 
 
 
local-files/zip/professor_zach_assistant_1750033356.zip DELETED
@@ -1,3 +0,0 @@
1
- version https://git-lfs.github.com/spec/v1
2
- oid sha256:59eee639803656a372b04affbada5007f221c7be9f534544f932b60a3ea5f116
3
- size 2775
 
 
 
 
local-files/zip/test_assistant_1750026513.zip DELETED
@@ -1,3 +0,0 @@
1
- version https://git-lfs.github.com/spec/v1
2
- oid sha256:8d5b897f2e81fca7bd64207ad86676725ad34005a72e9df3f7d754fffec69d5b
3
- size 2339
 
 
 
 
local-files/zip/zip.py DELETED
@@ -1,219 +0,0 @@
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!")