Spaces:
Sleeping
Sleeping
BeveledCube
commited on
Commit
•
f1f6374
1
Parent(s):
f0ed1e5
Pls be fixed
Browse files- Dockerfile +2 -0
- main.py +2 -2
- models/llama3.py +12 -0
Dockerfile
CHANGED
@@ -8,7 +8,9 @@ RUN pip install --upgrade pip
|
|
8 |
RUN pip install -r requirements.txt
|
9 |
|
10 |
RUN mkdir /api/cache
|
|
|
11 |
RUN chmod a+rwx /api/cache
|
|
|
12 |
|
13 |
EXPOSE 7860
|
14 |
|
|
|
8 |
RUN pip install -r requirements.txt
|
9 |
|
10 |
RUN mkdir /api/cache
|
11 |
+
RUN mkdir /api/models
|
12 |
RUN chmod a+rwx /api/cache
|
13 |
+
RUN chmod a+rwx /api/models
|
14 |
|
15 |
EXPOSE 7860
|
16 |
|
main.py
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
from flask import Flask, request, render_template, jsonify
|
2 |
-
from models import
|
3 |
|
4 |
app = Flask("AI API")
|
5 |
|
@@ -16,7 +16,7 @@ def receive_data():
|
|
16 |
data = request.get_json()
|
17 |
print("Prompt:", data["prompt"])
|
18 |
|
19 |
-
generated_text =
|
20 |
|
21 |
print("Response:", generated_text)
|
22 |
|
|
|
1 |
from flask import Flask, request, render_template, jsonify
|
2 |
+
from models import llama3
|
3 |
|
4 |
app = Flask("AI API")
|
5 |
|
|
|
16 |
data = request.get_json()
|
17 |
print("Prompt:", data["prompt"])
|
18 |
|
19 |
+
generated_text = llama3.generate(data["prompt"])
|
20 |
|
21 |
print("Response:", generated_text)
|
22 |
|
models/llama3.py
ADDED
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
2 |
+
|
3 |
+
model_name = "meta-llama/Meta-Llama-3-8B"
|
4 |
+
|
5 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
6 |
+
model = AutoModelForCausalLM.from_pretrained(model_name)
|
7 |
+
|
8 |
+
def generate(input_text):
|
9 |
+
input_ids = tokenizer.encode(input_text, return_tensors="pt")
|
10 |
+
output_ids = model.generate(input_ids, num_beams=5, no_repeat_ngram_size=2)
|
11 |
+
|
12 |
+
return tokenizer.decode(output_ids[0], skip_special_tokens=True)
|