Major upgrade
This commit is contained in:
parent
911555f358
commit
819b5b1e9d
10
app.py
10
app.py
@ -34,17 +34,13 @@ def generate_inference(token):
|
|||||||
"""Generate inference for given token."""
|
"""Generate inference for given token."""
|
||||||
if not token or token != "ETH":
|
if not token or token != "ETH":
|
||||||
error_msg = "Token is required" if not token else "Token not supported"
|
error_msg = "Token is required" if not token else "Token not supported"
|
||||||
return Response(
|
return Response(json.dumps({"error": error_msg}), status=400, mimetype='application/json')
|
||||||
json.dumps({"error": error_msg}), status=400, mimetype="application/json"
|
|
||||||
)
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
inference = get_eth_inference()
|
inference = get_eth_inference()
|
||||||
return jsonify({"value": str(inference)})
|
return Response(str(inference), status=200)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return Response(
|
return Response(json.dumps({"error": str(e)}), status=500, mimetype='application/json')
|
||||||
json.dumps({"error": str(e)}), status=500, mimetype="application/json"
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@app.route("/update")
|
@app.route("/update")
|
||||||
|
22
main.py
22
main.py
@ -9,19 +9,23 @@ INFERENCE_ADDRESS = os.environ["INFERENCE_API_ADDRESS"]
|
|||||||
def process(token_name):
|
def process(token_name):
|
||||||
response = requests.get(f"{INFERENCE_ADDRESS}/inference/{token_name}")
|
response = requests.get(f"{INFERENCE_ADDRESS}/inference/{token_name}")
|
||||||
content = response.text
|
content = response.text
|
||||||
print(content)
|
return content
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
# Your code logic with the parsed argument goes here
|
# Your code logic with the parsed argument goes here
|
||||||
try:
|
try:
|
||||||
if len(sys.argv) >= 3:
|
if len(sys.argv) < 5:
|
||||||
# Not using to discriminate by topicId for simplicity.
|
value = json.dumps({"error": f"Not enough arguments provided: {len(sys.argv)}, expected 4 arguments: topic_id, blockHeight, blockHeightEval, default_arg"})
|
||||||
# topic_id = sys.argv[1]
|
|
||||||
token_name = sys.argv[2]
|
|
||||||
else:
|
else:
|
||||||
token_name = "ETH"
|
topic_id = sys.argv[1]
|
||||||
process(token_name=token_name)
|
blockHeight = sys.argv[2]
|
||||||
|
blockHeightEval = sys.argv[3]
|
||||||
|
default_arg = sys.argv[4]
|
||||||
|
|
||||||
|
response_inference = process(token_name=default_arg)
|
||||||
|
response_dict = {"infererValue": response_inference}
|
||||||
|
value = json.dumps(response_dict)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
response = json.dumps({"error": {str(e)}})
|
value = json.dumps({"error": {str(e)}})
|
||||||
print(response)
|
print(value)
|
||||||
|
Loading…
Reference in New Issue
Block a user