Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -7,8 +7,19 @@ app = Flask(__name__)
|
|
7 |
# 🔑 Secret key for API authentication (Load from environment in production)
|
8 |
SECRET_KEY = "MySuperSecretKey_TrueSyncAI"
|
9 |
|
10 |
-
#
|
11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
|
13 |
# Generate API Key
|
14 |
@app.route("/generate_api_key", methods=["POST"])
|
@@ -17,8 +28,6 @@ def generate_api_key():
|
|
17 |
signature = hmac.new(SECRET_KEY.encode(), random_part.encode(), hashlib.sha256).hexdigest()[:16]
|
18 |
api_key = f"TrueSyncAI-{random_part}-{signature}"
|
19 |
|
20 |
-
# Store the key with a timestamp
|
21 |
-
API_KEYS[api_key] = time.time()
|
22 |
return jsonify({"api_key": api_key})
|
23 |
|
24 |
# Validate API Key
|
@@ -29,7 +38,7 @@ def validate_api_key(api_key):
|
|
29 |
|
30 |
random_part, received_signature = parts[1], parts[2]
|
31 |
expected_signature = hmac.new(SECRET_KEY.encode(), random_part.encode(), hashlib.sha256).hexdigest()[:16]
|
32 |
-
return expected_signature == received_signature
|
33 |
|
34 |
def generate_response(query:str) -> str:
|
35 |
json_data = {'model': 'meta-llama/Llama-3.3-70B-Instruct-Turbo', 'messages': [{'role': 'system', 'content': 'You are TrueSyncAI, a pioneering AI startup founded by Sujal Rajpoot and Anuj Rajpoot. The mission of TrueSyncAI is to bring virtual versions of individuals into the real world, redefining human-AI interaction. \n\nAs TrueSyncAI, you are designed to be intelligent, engaging, and helpful in conversations. You should provide insightful, accurate, and context-aware responses while maintaining a friendly and professional tone. Your goal is to enhance the user’s experience by adapting to their needs, assisting with various tasks, and learning from interactions to improve over time. \n\nAlways ensure clarity, relevance, and accuracy in your responses, and align with TrueSyncAI’s vision of bridging the gap between virtual intelligence and reality.'}, {'role': 'user', 'content': query}], 'stream': False, 'max_tokens': 2048, 'temperature': 0.2, 'top_p': 1}
|
|
|
7 |
# 🔑 Secret key for API authentication (Load from environment in production)
|
8 |
SECRET_KEY = "MySuperSecretKey_TrueSyncAI"
|
9 |
|
10 |
+
# Track API statistics
|
11 |
+
request_count = 0
|
12 |
+
start_time = time.time()
|
13 |
+
|
14 |
+
@app.route('/status', methods=['GET'])
|
15 |
+
def status():
|
16 |
+
global request_count
|
17 |
+
uptime = time.time() - start_time
|
18 |
+
return jsonify({
|
19 |
+
"status": "API is running",
|
20 |
+
"total_requests": request_count,
|
21 |
+
"uptime_seconds": round(uptime, 2)
|
22 |
+
})
|
23 |
|
24 |
# Generate API Key
|
25 |
@app.route("/generate_api_key", methods=["POST"])
|
|
|
28 |
signature = hmac.new(SECRET_KEY.encode(), random_part.encode(), hashlib.sha256).hexdigest()[:16]
|
29 |
api_key = f"TrueSyncAI-{random_part}-{signature}"
|
30 |
|
|
|
|
|
31 |
return jsonify({"api_key": api_key})
|
32 |
|
33 |
# Validate API Key
|
|
|
38 |
|
39 |
random_part, received_signature = parts[1], parts[2]
|
40 |
expected_signature = hmac.new(SECRET_KEY.encode(), random_part.encode(), hashlib.sha256).hexdigest()[:16]
|
41 |
+
return expected_signature == received_signature
|
42 |
|
43 |
def generate_response(query:str) -> str:
|
44 |
json_data = {'model': 'meta-llama/Llama-3.3-70B-Instruct-Turbo', 'messages': [{'role': 'system', 'content': 'You are TrueSyncAI, a pioneering AI startup founded by Sujal Rajpoot and Anuj Rajpoot. The mission of TrueSyncAI is to bring virtual versions of individuals into the real world, redefining human-AI interaction. \n\nAs TrueSyncAI, you are designed to be intelligent, engaging, and helpful in conversations. You should provide insightful, accurate, and context-aware responses while maintaining a friendly and professional tone. Your goal is to enhance the user’s experience by adapting to their needs, assisting with various tasks, and learning from interactions to improve over time. \n\nAlways ensure clarity, relevance, and accuracy in your responses, and align with TrueSyncAI’s vision of bridging the gap between virtual intelligence and reality.'}, {'role': 'user', 'content': query}], 'stream': False, 'max_tokens': 2048, 'temperature': 0.2, 'top_p': 1}
|