Spaces:
Sleeping
Sleeping
Create self_update_test.py
Browse files- self_update_test.py +56 -0
self_update_test.py
ADDED
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
# self_update_test.py
|
3 |
+
import os
|
4 |
+
import requests
|
5 |
+
import time
|
6 |
+
|
7 |
+
def test_self_update():
|
8 |
+
print("Testing self-update capability...")
|
9 |
+
|
10 |
+
# Original response handler content
|
11 |
+
original_content = """def generate_response(prompt, tokenizer, model):
|
12 |
+
inputs = tokenizer(prompt, return_tensors="pt")
|
13 |
+
outputs = model.generate(**inputs, max_length=200)
|
14 |
+
return tokenizer.decode(outputs[0], skip_special_tokens=True)"""
|
15 |
+
|
16 |
+
# Updated version
|
17 |
+
updated_content = """def generate_response(prompt, tokenizer, model):
|
18 |
+
# Improved version with better parameters
|
19 |
+
inputs = tokenizer(prompt, return_tensors="pt")
|
20 |
+
outputs = model.generate(
|
21 |
+
**inputs,
|
22 |
+
max_length=300,
|
23 |
+
temperature=0.7,
|
24 |
+
top_p=0.9,
|
25 |
+
repetition_penalty=1.1
|
26 |
+
)
|
27 |
+
return tokenizer.decode(outputs[0], skip_special_tokens=True)"""
|
28 |
+
|
29 |
+
# Save original version
|
30 |
+
with open("response_handler.py", "w") as f:
|
31 |
+
f.write(original_content)
|
32 |
+
|
33 |
+
# Start the app (in a real test, this would be a separate process)
|
34 |
+
print("Starting with original version...")
|
35 |
+
|
36 |
+
# Simulate update process
|
37 |
+
print("Triggering update...")
|
38 |
+
response = requests.post("http://localhost:7860/api/predict", json={"data": ["/update"]})
|
39 |
+
print(f"Update result: {response.json()['data']}")
|
40 |
+
|
41 |
+
# Verify update
|
42 |
+
time.sleep(2)
|
43 |
+
with open("response_handler.py", "r") as f:
|
44 |
+
current_content = f.read()
|
45 |
+
|
46 |
+
if updated_content in current_content:
|
47 |
+
print("✅ Self-update successful!")
|
48 |
+
else:
|
49 |
+
print("❌ Self-update failed")
|
50 |
+
|
51 |
+
# Restore original
|
52 |
+
with open("response_handler.py", "w") as f:
|
53 |
+
f.write(original_content)
|
54 |
+
|
55 |
+
if __name__ == "__main__":
|
56 |
+
test_self_update()
|