Spaces:
Sleeping
Sleeping
Commit
·
233b98c
1
Parent(s):
b4930ce
added model reponse
Browse files
app.py
CHANGED
@@ -1,11 +1,26 @@
|
|
1 |
from flask import Flask, jsonify, request
|
2 |
-
from flask_cors import CORS
|
|
|
|
|
3 |
import os
|
4 |
|
5 |
app = Flask(__name__)
|
6 |
|
7 |
# Enable CORS for specific origins
|
8 |
CORS(app, resources={r"api/predict/*": {"origins": ["http://localhost:3000", "https://main.dbn2ikif9ou3g.amplifyapp.com"]}})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
|
10 |
@app.route("/", methods=["GET"])
|
11 |
def handle_get_request():
|
@@ -27,9 +42,13 @@ def handle_post_request():
|
|
27 |
# Extract the 'inputs' and 'authtoken' from the JSON data
|
28 |
message = data.get("inputs", "No message provided.")
|
29 |
new_token = os.getenv("HF_TOKEN")
|
30 |
-
|
|
|
|
|
|
|
|
|
31 |
return jsonify({
|
32 |
-
"received_message":
|
33 |
"status": "POST request successful!"
|
34 |
})
|
35 |
|
|
|
1 |
from flask import Flask, jsonify, request
|
2 |
+
from flask_cors import CORS
|
3 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM, GenerationConfig
|
4 |
+
from huggingface_hub import login
|
5 |
import os
|
6 |
|
7 |
app = Flask(__name__)
|
8 |
|
9 |
# Enable CORS for specific origins
|
10 |
CORS(app, resources={r"api/predict/*": {"origins": ["http://localhost:3000", "https://main.dbn2ikif9ou3g.amplifyapp.com"]}})
|
11 |
+
|
12 |
+
model_id = "YALCINKAYA/opsgenius-large"
|
13 |
+
|
14 |
+
model, tokenizer = get_model_and_tokenizer(model_id)
|
15 |
+
|
16 |
+
def generate_response(user_input):
|
17 |
+
prompt = formatted_prompt(user_input)
|
18 |
+
|
19 |
+
response = prompt
|
20 |
+
response
|
21 |
+
|
22 |
+
def formatted_prompt(question) -> str:
|
23 |
+
return f"<|im_start|>user\n{question}<|im_end|>\n<|im_start|>assistant:"
|
24 |
|
25 |
@app.route("/", methods=["GET"])
|
26 |
def handle_get_request():
|
|
|
42 |
# Extract the 'inputs' and 'authtoken' from the JSON data
|
43 |
message = data.get("inputs", "No message provided.")
|
44 |
new_token = os.getenv("HF_TOKEN")
|
45 |
+
|
46 |
+
# Generate a response from the model
|
47 |
+
model_response = generate_response(user_input)
|
48 |
+
|
49 |
+
# Return a JSON response including the generated response
|
50 |
return jsonify({
|
51 |
+
"received_message": model_response,
|
52 |
"status": "POST request successful!"
|
53 |
})
|
54 |
|