Spaces:
Runtime error
Runtime error
ultralight99
commited on
upload app.py
Browse files
app.py
ADDED
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
2 |
+
from flask import Flask, request, jsonify
|
3 |
+
|
4 |
+
app = Flask(__name__)
|
5 |
+
|
6 |
+
model_name = "gordicaleksa/YugoGPT"
|
7 |
+
model = AutoModelForCausalLM.from_pretrained(model_name)
|
8 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
9 |
+
|
10 |
+
@app.route("/chat", methods=["POST"])
|
11 |
+
def chat():
|
12 |
+
user_input = request.json.get("inputs")
|
13 |
+
inputs = tokenizer.encode(user_input, return_tensors="pt")
|
14 |
+
outputs = model.generate(inputs, max_length=100, num_return_sequences=1)
|
15 |
+
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
16 |
+
return jsonify({"response": response})
|
17 |
+
|
18 |
+
if __name__ == "__main__":
|
19 |
+
app.run(host="0.0.0.0", port=8080)
|