Update app.py
Browse files
app.py
CHANGED
|
@@ -122,6 +122,55 @@ def log():
|
|
| 122 |
json.dump(existing_data, f)
|
| 123 |
return jsonify({'message': 'Data added successfully', 'data': existing_data}), 201
|
| 124 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 125 |
if __name__=='__main__':
|
| 126 |
debug_mode = os.getenv('FLASK_DEBUG', 'False').lower() in ['true', '1', 't']
|
| 127 |
app.run(host='0.0.0.0', port='7860', debug=debug_mode)
|
|
|
|
| 122 |
json.dump(existing_data, f)
|
| 123 |
return jsonify({'message': 'Data added successfully', 'data': existing_data}), 201
|
| 124 |
|
| 125 |
+
@app.route("/demo_inference", methods=['GET'])
|
| 126 |
+
@cross_origin()
|
| 127 |
+
def demo_inference():
|
| 128 |
+
args = request.args
|
| 129 |
+
# model_id = "meta-llama/Llama-3.2-11B-Vision-Instruct"
|
| 130 |
+
model_id = args.get('model_id', default="meta-llama/Llama-4-Scout-17B-16E-Instruct")
|
| 131 |
+
temperature = args.get('temperature', default=0.5)
|
| 132 |
+
max_new_tokens = args.get('max_new_tokens', default=1000)
|
| 133 |
+
|
| 134 |
+
hf_token, hf_url = get_credentials.get_credentials()
|
| 135 |
+
|
| 136 |
+
prompt = args.get('prompt')
|
| 137 |
+
|
| 138 |
+
API_URL = "https://router.huggingface.co/together/v1/chat/completions"
|
| 139 |
+
headers = {
|
| 140 |
+
"Authorization": f"Bearer {hf_token}",
|
| 141 |
+
}
|
| 142 |
+
|
| 143 |
+
response = requests.post(
|
| 144 |
+
API_URL,
|
| 145 |
+
headers=headers,
|
| 146 |
+
json={
|
| 147 |
+
"messages": [
|
| 148 |
+
{
|
| 149 |
+
"role": "user",
|
| 150 |
+
"content": [
|
| 151 |
+
{
|
| 152 |
+
"type": "text",
|
| 153 |
+
"text": prompt
|
| 154 |
+
},
|
| 155 |
+
]
|
| 156 |
+
}
|
| 157 |
+
],
|
| 158 |
+
"model": model_id,
|
| 159 |
+
'temperature': temperature,
|
| 160 |
+
'max_new_tokens': max_new_tokens,
|
| 161 |
+
}
|
| 162 |
+
)
|
| 163 |
+
try:
|
| 164 |
+
response = response.json()["choices"][0]["message"]
|
| 165 |
+
response.update({
|
| 166 |
+
'model_id': model_id,
|
| 167 |
+
'temperature': temperature,
|
| 168 |
+
'max_new_tokens': max_new_tokens,
|
| 169 |
+
})
|
| 170 |
+
return response
|
| 171 |
+
except:
|
| 172 |
+
return response.text, response.status_code
|
| 173 |
+
|
| 174 |
if __name__=='__main__':
|
| 175 |
debug_mode = os.getenv('FLASK_DEBUG', 'False').lower() in ['true', '1', 't']
|
| 176 |
app.run(host='0.0.0.0', port='7860', debug=debug_mode)
|