Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,6 +1,7 @@
|
|
1 |
### 文言文翻译
|
2 |
|
3 |
import simplestart as ss
|
|
|
4 |
import json
|
5 |
import time
|
6 |
###import mymodule as mm
|
@@ -21,8 +22,17 @@ def mychange(event):
|
|
21 |
|
22 |
def predict():
|
23 |
ss.message(ss.session.text)
|
|
|
|
|
24 |
#response = mm.predict(mytext.value, ss.session.method)
|
25 |
#ss.session["result"] = response
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
|
27 |
|
28 |
def demo1(state, value):
|
|
|
1 |
### 文言文翻译
|
2 |
|
3 |
import simplestart as ss
|
4 |
+
import requests
|
5 |
import json
|
6 |
import time
|
7 |
###import mymodule as mm
|
|
|
22 |
|
23 |
def predict():
|
24 |
ss.message(ss.session.text)
|
25 |
+
method = str(ss.session.method)
|
26 |
+
response = inference(ss.session.text, method)
|
27 |
#response = mm.predict(mytext.value, ss.session.method)
|
28 |
#ss.session["result"] = response
|
29 |
+
ss.write(response)
|
30 |
+
|
31 |
+
def inference(input_text, method):
|
32 |
+
url = "http://0.0.0.0:8080/process" # 假设POST请求的路径是 /process
|
33 |
+
data = {"text": input_text, "method": method} # 将 input_text 和 method 作为 JSON 数据发送
|
34 |
+
res = requests.post(url, json=data) # 发送 POST 请求,传递 JSON 数据
|
35 |
+
return res.json() # 假设服务器返回 JSON 响应
|
36 |
|
37 |
|
38 |
def demo1(state, value):
|