Spaces:
Sleeping
Sleeping
test2023h5
commited on
Commit
•
df23b68
1
Parent(s):
49f2fc5
Update main.py
Browse files
main.py
CHANGED
@@ -6,6 +6,7 @@ from peft import PeftModel, get_peft_config
|
|
6 |
import json
|
7 |
import torch
|
8 |
|
|
|
9 |
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
|
10 |
|
11 |
|
@@ -32,6 +33,7 @@ model = base_model.to(device)
|
|
32 |
|
33 |
# 加载 tokenizer
|
34 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
|
|
35 |
|
36 |
def format_instruction(task, text):
|
37 |
string = f"""### 指令:
|
@@ -107,17 +109,17 @@ async def say_hello():
|
|
107 |
# POST请求接口
|
108 |
@app.post("/process")
|
109 |
async def process_text(request: ProcessRequest):
|
110 |
-
if request.method == 0:
|
111 |
#processed_text = request.text.upper()
|
112 |
processed_text = "predict(request.text, 0)"
|
113 |
-
elif request.method == 1:
|
114 |
#processed_text = request.text.lower()
|
115 |
processed_text = "predict(request.text, 1)"
|
116 |
-
elif request.method == 2:
|
117 |
processed_text = "request.text[::-1]" # 反转字符串
|
118 |
else:
|
119 |
processed_text = "request.text"
|
120 |
|
121 |
return {"original_text": request.text, "processed_text": processed_text, "method": request.method}
|
122 |
|
123 |
-
print("fastapi done")
|
|
|
6 |
import json
|
7 |
import torch
|
8 |
|
9 |
+
'''
|
10 |
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
|
11 |
|
12 |
|
|
|
33 |
|
34 |
# 加载 tokenizer
|
35 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
36 |
+
'''
|
37 |
|
38 |
def format_instruction(task, text):
|
39 |
string = f"""### 指令:
|
|
|
109 |
# POST请求接口
|
110 |
@app.post("/process")
|
111 |
async def process_text(request: ProcessRequest):
|
112 |
+
if request.method == "0":
|
113 |
#processed_text = request.text.upper()
|
114 |
processed_text = "predict(request.text, 0)"
|
115 |
+
elif request.method == "1":
|
116 |
#processed_text = request.text.lower()
|
117 |
processed_text = "predict(request.text, 1)"
|
118 |
+
elif request.method == "2":
|
119 |
processed_text = "request.text[::-1]" # 反转字符串
|
120 |
else:
|
121 |
processed_text = "request.text"
|
122 |
|
123 |
return {"original_text": request.text, "processed_text": processed_text, "method": request.method}
|
124 |
|
125 |
+
print("fastapi done 1")
|