3v324v23 commited on
Commit
eb4f048
ยท
0 Parent(s):

Clean deployment for HF

Browse files
Files changed (14) hide show
  1. .dockerignore +8 -0
  2. .gitattributes +35 -0
  3. .gitignore +31 -0
  4. .python-version +1 -0
  5. Dockerfile +68 -0
  6. INFO (2).md +62 -0
  7. README.md +17 -0
  8. chat_interactive.py +221 -0
  9. models.json +0 -0
  10. requirements.txt +9 -0
  11. src/__init__.py +0 -0
  12. src/lol.py +0 -0
  13. src/main.py +0 -0
  14. vercel.json +15 -0
.dockerignore ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ venv/
2
+ .git/
3
+ .gitignore
4
+ __pycache__/
5
+ *.pyc
6
+ .python-version
7
+ .vercel/
8
+ *.log
.gitattributes ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ *.7z filter=lfs diff=lfs merge=lfs -text
2
+ *.arrow filter=lfs diff=lfs merge=lfs -text
3
+ *.bin filter=lfs diff=lfs merge=lfs -text
4
+ *.bz2 filter=lfs diff=lfs merge=lfs -text
5
+ *.ckpt filter=lfs diff=lfs merge=lfs -text
6
+ *.ftz filter=lfs diff=lfs merge=lfs -text
7
+ *.gz filter=lfs diff=lfs merge=lfs -text
8
+ *.h5 filter=lfs diff=lfs merge=lfs -text
9
+ *.joblib filter=lfs diff=lfs merge=lfs -text
10
+ *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
+ *.mlmodel filter=lfs diff=lfs merge=lfs -text
12
+ *.model filter=lfs diff=lfs merge=lfs -text
13
+ *.msgpack filter=lfs diff=lfs merge=lfs -text
14
+ *.npy filter=lfs diff=lfs merge=lfs -text
15
+ *.npz filter=lfs diff=lfs merge=lfs -text
16
+ *.onnx filter=lfs diff=lfs merge=lfs -text
17
+ *.ot filter=lfs diff=lfs merge=lfs -text
18
+ *.parquet filter=lfs diff=lfs merge=lfs -text
19
+ *.pb filter=lfs diff=lfs merge=lfs -text
20
+ *.pickle filter=lfs diff=lfs merge=lfs -text
21
+ *.pkl filter=lfs diff=lfs merge=lfs -text
22
+ *.pt filter=lfs diff=lfs merge=lfs -text
23
+ *.pth filter=lfs diff=lfs merge=lfs -text
24
+ *.rar filter=lfs diff=lfs merge=lfs -text
25
+ *.safetensors filter=lfs diff=lfs merge=lfs -text
26
+ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
27
+ *.tar.* filter=lfs diff=lfs merge=lfs -text
28
+ *.tar filter=lfs diff=lfs merge=lfs -text
29
+ *.tflite filter=lfs diff=lfs merge=lfs -text
30
+ *.tgz filter=lfs diff=lfs merge=lfs -text
31
+ *.wasm filter=lfs diff=lfs merge=lfs -text
32
+ *.xz filter=lfs diff=lfs merge=lfs -text
33
+ *.zip filter=lfs diff=lfs merge=lfs -text
34
+ *.zst filter=lfs diff=lfs merge=lfs -text
35
+ *tfevents* filter=lfs diff=lfs merge=lfs -text
.gitignore ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ venv/
2
+ *webui_secret_key
3
+ *cache_ggshield
4
+ config.json
5
+
6
+ # Exclude heavy cache/temporary data
7
+ chrome_profile/**/Cache/
8
+ chrome_profile/**/Code Cache/
9
+ chrome_profile/**/GPUCache/
10
+ chrome_profile/**/GrShaderCache/
11
+ chrome_profile/**/ShaderCache/
12
+ chrome_profile/**/optimization_guide_model_store/
13
+ chrome_profile/**/OptimizationGuidePredictionModels/
14
+ chrome_profile/**/BrowserMetrics/
15
+ chrome_profile/**/Crashpad/
16
+ chrome_profile/**/VideoDecodeStats/
17
+ chrome_profile/**/Platform Notifications/
18
+ chrome_profile/**/blob_storage/
19
+ chrome_profile/**/File System/
20
+ chrome_profile/chrome_debug.log
21
+ chrome_profile/*.log
22
+ chrome_profile/**/*.tmp
23
+ chrome_profile/**/*.bak
24
+
25
+ # Keep Session/Login data (Required for arena.ai)
26
+ !chrome_profile/**/Local Storage/
27
+ !chrome_profile/**/Session Storage/
28
+ # Removed IndexedDB to save space
29
+ !chrome_profile/**/Cookies
30
+ !chrome_profile/**/Web Data
31
+ !chrome_profile/**/Login Data
.python-version ADDED
@@ -0,0 +1 @@
 
 
1
+ 3.12.10
Dockerfile ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.10-slim
2
+
3
+ # Install system dependencies
4
+ RUN apt-get update && apt-get install -y \
5
+ wget \
6
+ gnupg \
7
+ unzip \
8
+ curl \
9
+ libnss3 \
10
+ libnspr4 \
11
+ libatk1.0-0 \
12
+ libatk-bridge2.0-0 \
13
+ libcups2 \
14
+ libdrm2 \
15
+ libdbus-1-3 \
16
+ libxkbcommon0 \
17
+ libxcomposite1 \
18
+ libxdamage1 \
19
+ libxext6 \
20
+ libxfixes3 \
21
+ libxrandr2 \
22
+ libgbm1 \
23
+ libpango-1.0-0 \
24
+ libcairo2 \
25
+ libasound2 \
26
+ fonts-liberation \
27
+ libappindicator3-1 \
28
+ libxshmfence1 \
29
+ lsb-release \
30
+ xdg-utils \
31
+ --no-install-recommends \
32
+ && rm -rf /var/lib/apt/lists/*
33
+
34
+ # Install Google Chrome
35
+ RUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - \
36
+ && echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list \
37
+ && apt-get update \
38
+ && apt-get install -y google-chrome-stable \
39
+ && rm -rf /var/lib/apt/lists/*
40
+
41
+ # Create a non-root user (Hugging Face best practice)
42
+ RUN useradd -m -u 1000 user
43
+ USER user
44
+ ENV PATH="/home/user/.local/bin:$PATH"
45
+
46
+ # Set working directory
47
+ WORKDIR /app
48
+
49
+ # Copy requirements and install
50
+ COPY --chown=user requirements.txt .
51
+ RUN pip install --no-cache-dir --user -r requirements.txt
52
+
53
+ # Download Camoufox/Firefox binaries
54
+ RUN python3 -m camoufox fetch
55
+
56
+ # Copy the rest of the application with proper ownership
57
+ COPY --chown=user . .
58
+
59
+ # Set environment variables
60
+ ENV PORT=7860
61
+ ENV HEADLESS=true
62
+ ENV PYTHONUNBUFFERED=1
63
+
64
+ # Expose the port
65
+ EXPOSE 7860
66
+
67
+ # Command to run the application
68
+ CMD ["python", "src/lol.py"]
INFO (2).md ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Here is the updated plan for `main.py`.
2
+
3
+ ###The Plan1. **Modify `get_recaptcha_v3_token**`:
4
+ * **Headless Mode:** Ensure `AsyncCamoufox(headless=False, ...)` is set.
5
+ * **Navigation:** Go to `https://lmarena.ai/`.
6
+ * **Cloudflare Challenge:** Immediately after loading, inject a check for the Turnstile widget.
7
+ * Use a loop to check if the page title is "Just a moment..." or if the Turnstile selector exists.
8
+ * Call your existing `click_turnstile(page)` function if detected.
9
+ * Wait for the challenge to clear (title change or selector disappearance).
10
+
11
+
12
+ * **Remove Auth Scraper:** Delete the loop that waits specifically for the `arena-auth-prod-v1` cookie. We only care about passing the challenge so the `grecaptcha` library loads.
13
+ * **Proceed:** Continue to the existing "Side-Channel" logic (human pause -> wait for library -> trigger execution).
14
+
15
+
16
+
17
+ ###Edit Instructions for `main.py`**Step 1:** In `get_recaptcha_v3_token`, confirm the browser init line is:
18
+
19
+ ```python
20
+ async with AsyncCamoufox(headless=False, main_world_eval=True) as browser:
21
+
22
+ ```
23
+
24
+ **Step 2:** Replace the "Auth Loop" section (approx lines 180-205 in your provided code) with this Challenge Logic:
25
+
26
+ ```python
27
+ # ... inside get_recaptcha_v3_token ...
28
+ debug_print(" ๐ŸŒ Navigating to lmarena.ai...")
29
+ await page.goto("https://lmarena.ai/", wait_until="domcontentloaded")
30
+
31
+ # --- NEW: Cloudflare/Turnstile Pass-Through ---
32
+ debug_print(" ๐Ÿ›ก๏ธ Checking for Cloudflare Turnstile...")
33
+
34
+ # Allow time for the widget to render if it's going to
35
+ try:
36
+ # Check for challenge title or widget presence
37
+ for _ in range(5):
38
+ title = await page.title()
39
+ if "Just a moment" in title:
40
+ debug_print(" ๐Ÿ”’ Cloudflare challenge active. Attempting to click...")
41
+ clicked = await click_turnstile(page)
42
+ if clicked:
43
+ debug_print(" โœ… Clicked Turnstile.")
44
+ # Give it time to verify
45
+ await asyncio.sleep(3)
46
+ else:
47
+ # If title is normal, we might still have a widget on the page
48
+ await click_turnstile(page)
49
+ break
50
+ await asyncio.sleep(1)
51
+
52
+ # Wait for the page to actually settle into the main app
53
+ await page.wait_for_load_state("domcontentloaded")
54
+ except Exception as e:
55
+ debug_print(f" โš ๏ธ Error handling Turnstile: {e}")
56
+ # ----------------------------------------------
57
+
58
+ # 1. Wake up the page (Humanize) - Keep this as is
59
+ debug_print(" ๐Ÿ–ฑ๏ธ Waking up page...")
60
+ # ... rest of function ...
61
+
62
+ ```
README.md ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: Arena
3
+ emoji: ๐ŸŸ๏ธ
4
+ colorFrom: blue
5
+ colorTo: indigo
6
+ sdk: docker
7
+ pinned: false
8
+ ---
9
+
10
+ # Arena Bridge
11
+
12
+ Arena for Hugging Face Spaces.
13
+
14
+ ## Deployment Details
15
+ - **SDK**: Docker
16
+ - **Port**: 7860
17
+ - **Base image**: python:3.10-slim with Chrome
chat_interactive.py ADDED
@@ -0,0 +1,221 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Interactive chat script using OpenAI Python library with LMArena Bridge
3
+ Allows you to have a conversation with any model available through the bridge
4
+ """
5
+
6
+ from openai import OpenAI
7
+ import sys
8
+
9
+ # Configuration
10
+ BASE_URL = "http://localhost:7860/v1"
11
+ API_KEY = "sk-lmab-09a84bbc-d5a2-4d34-a62c-b16e8c618179" # Replace with your API key
12
+
13
+ def list_available_models(client):
14
+ """List all available models"""
15
+ try:
16
+ models = client.models.list()
17
+ return [model.id for model in models.data]
18
+ except Exception as e:
19
+ print(f"Error fetching models: {e}")
20
+ return []
21
+
22
+ def chat_session(client, model_name):
23
+ """Run an interactive chat session"""
24
+ print(f"\n{'='*60}")
25
+ print(f"๐Ÿค– Chat Session with {model_name}")
26
+ print(f"{'='*60}")
27
+
28
+ # Ask for system prompt
29
+ print("\n๐Ÿ“‹ System Prompt (optional):")
30
+ print("Set the behavior/personality of the assistant.")
31
+ print("Press Enter to skip, or type your system prompt below:")
32
+ system_prompt = input("System: ").strip()
33
+
34
+ conversation_history = []
35
+
36
+ # Add system message if provided
37
+ if system_prompt:
38
+ conversation_history.append({
39
+ "role": "system",
40
+ "content": system_prompt
41
+ })
42
+ print(f"โœ… System prompt set: {system_prompt[:50]}{'...' if len(system_prompt) > 50 else ''}")
43
+
44
+ print(f"\n{'='*60}")
45
+ print("Type your messages below. Commands:")
46
+ print(" - 'exit' or 'quit' to end the session")
47
+ print(" - 'clear' to start a new conversation")
48
+ print(" - 'system' to view/change system prompt")
49
+ print(" - 'models' to switch models")
50
+ print(f"{'='*60}\n")
51
+
52
+ while True:
53
+ # Get user input
54
+ try:
55
+ user_input = input("You: ").strip()
56
+ except (EOFError, KeyboardInterrupt):
57
+ print("\n\n๐Ÿ‘‹ Goodbye!")
58
+ break
59
+
60
+ # Handle commands FIRST before adding to history
61
+ if not user_input:
62
+ continue
63
+
64
+ if user_input.lower() in ['exit', 'quit']:
65
+ print("\n๐Ÿ‘‹ Goodbye!")
66
+ break
67
+
68
+ if user_input.lower() == 'clear':
69
+ # Keep system prompt if it exists
70
+ system_msg = None
71
+ if conversation_history and conversation_history[0]["role"] == "system":
72
+ system_msg = conversation_history[0]
73
+
74
+ conversation_history = []
75
+ if system_msg:
76
+ conversation_history.append(system_msg)
77
+ print("\n๐Ÿ”„ Conversation cleared!\n")
78
+ continue
79
+
80
+ if user_input.lower() == 'system':
81
+ # Show or update system prompt
82
+ current_system = None
83
+ if conversation_history and conversation_history[0]["role"] == "system":
84
+ current_system = conversation_history[0]["content"]
85
+ print(f"\n๐Ÿ“‹ Current system prompt:\n{current_system}\n")
86
+ else:
87
+ print("\n๐Ÿ“‹ No system prompt set.\n")
88
+
89
+ print("Enter new system prompt (or press Enter to keep current):")
90
+ new_system = input("System: ").strip()
91
+
92
+ if new_system:
93
+ # Remove old system message if exists
94
+ if conversation_history and conversation_history[0]["role"] == "system":
95
+ conversation_history.pop(0)
96
+
97
+ # Add new system message at the start
98
+ conversation_history.insert(0, {
99
+ "role": "system",
100
+ "content": new_system
101
+ })
102
+ print(f"โœ… System prompt updated: {new_system[:50]}{'...' if len(new_system) > 50 else ''}\n")
103
+ else:
104
+ print("System prompt unchanged.\n")
105
+ continue
106
+
107
+ if user_input.lower() == 'models':
108
+ return 'switch_model'
109
+
110
+ # Add user message to history (only if not a command)
111
+ conversation_history.append({
112
+ "role": "user",
113
+ "content": user_input
114
+ })
115
+
116
+ # Get response from API with streaming
117
+ try:
118
+ print("Assistant: ", end="", flush=True)
119
+
120
+ stream = client.chat.completions.create(
121
+ model=model_name,
122
+ messages=conversation_history,
123
+ stream=True # Enable streaming
124
+ )
125
+
126
+ assistant_message = ""
127
+ for chunk in stream:
128
+ if chunk.choices[0].delta.content is not None:
129
+ content = chunk.choices[0].delta.content
130
+ print(content, end="", flush=True)
131
+ assistant_message += content
132
+
133
+ print() # New line after streaming completes
134
+
135
+ # Add assistant response to history
136
+ conversation_history.append({
137
+ "role": "assistant",
138
+ "content": assistant_message
139
+ })
140
+
141
+ print() # Empty line for readability
142
+
143
+ except Exception as e:
144
+ print(f"\nโŒ Error: {e}\n")
145
+ # Remove the failed user message from history
146
+ conversation_history.pop()
147
+
148
+ def select_model(client, models):
149
+ """Let user select a model"""
150
+ print("\n๐Ÿ“‹ Available Models:")
151
+ print("-" * 60)
152
+
153
+ for i, model in enumerate(models, 1):
154
+ print(f"{i}. {model}")
155
+
156
+ print("-" * 60)
157
+
158
+ while True:
159
+ try:
160
+ choice = input("\nSelect a model number (or 'q' to quit): ").strip()
161
+
162
+ if choice.lower() == 'q':
163
+ return None
164
+
165
+ choice_num = int(choice)
166
+ if 1 <= choice_num <= len(models):
167
+ return models[choice_num - 1]
168
+ else:
169
+ print(f"Please enter a number between 1 and {len(models)}")
170
+ except ValueError:
171
+ print("Please enter a valid number or 'q' to quit")
172
+ except (EOFError, KeyboardInterrupt):
173
+ print("\n")
174
+ return None
175
+
176
+ def main():
177
+ """Main function"""
178
+ print("=" * 60)
179
+ print("๐Ÿš€ LMArena Bridge - Interactive Chat")
180
+ print("=" * 60)
181
+
182
+ # Initialize OpenAI client
183
+ try:
184
+ client = OpenAI(
185
+ api_key=API_KEY,
186
+ base_url=BASE_URL
187
+ )
188
+ print("โœ… Connected to LMArena Bridge")
189
+ except Exception as e:
190
+ print(f"โŒ Failed to initialize client: {e}")
191
+ return
192
+
193
+ # Get available models
194
+ print("๐Ÿ“ก Fetching available models...")
195
+ models = list_available_models(client)
196
+
197
+ if not models:
198
+ print("โŒ No models available. Please check your API key and server status.")
199
+ return
200
+
201
+ print(f"โœ… Found {len(models)} models")
202
+
203
+ # Main loop
204
+ while True:
205
+ selected_model = select_model(client, models)
206
+
207
+ if selected_model is None:
208
+ print("\n๐Ÿ‘‹ Goodbye!")
209
+ break
210
+
211
+ result = chat_session(client, selected_model)
212
+
213
+ if result != 'switch_model':
214
+ break
215
+
216
+ if __name__ == "__main__":
217
+ try:
218
+ main()
219
+ except KeyboardInterrupt:
220
+ print("\n\n๐Ÿ‘‹ Goodbye!")
221
+ sys.exit(0)
models.json ADDED
The diff for this file is too large to render. See raw diff
 
requirements.txt ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ fastapi
2
+ uvicorn
3
+ nodriver
4
+ httpx
5
+ curl_cffi>=0.6.0
6
+ python-multipart
7
+ python-dotenv
8
+ camoufox[geoip]
9
+ camoufox
src/__init__.py ADDED
File without changes
src/lol.py ADDED
The diff for this file is too large to render. See raw diff
 
src/main.py ADDED
The diff for this file is too large to render. See raw diff
 
vercel.json ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "version": 2,
3
+ "builds": [
4
+ {
5
+ "src": "src/main.py",
6
+ "use": "@vercel/python"
7
+ }
8
+ ],
9
+ "routes": [
10
+ {
11
+ "src": "/(.*)",
12
+ "dest": "src/main.py"
13
+ }
14
+ ]
15
+ }