YSXysx commited on
Commit
be1c83b
·
1 Parent(s): d891488

test network connection

Browse files
Files changed (1) hide show
  1. main.py +23 -1
main.py CHANGED
@@ -3,6 +3,13 @@ from fastapi.staticfiles import StaticFiles
3
  from fastapi.responses import FileResponse
4
 
5
  from transformers import pipeline
 
 
 
 
 
 
 
6
 
7
  app = FastAPI()
8
 
@@ -11,7 +18,22 @@ pipe_flan = pipeline("text2text-generation", model="google/flan-t5-small")
11
  @app.get("/infer_t5")
12
  def t5(input):
13
  output = pipe_flan(input)
14
- return {"output": 123}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
 
16
  app.mount("/", StaticFiles(directory="static", html=True), name="static")
17
 
 
3
  from fastapi.responses import FileResponse
4
 
5
  from transformers import pipeline
6
+ import requests
7
+
8
+
9
+
10
+
11
+
12
+
13
 
14
  app = FastAPI()
15
 
 
18
  @app.get("/infer_t5")
19
  def t5(input):
20
  output = pipe_flan(input)
21
+ # 要访问的网页 URL
22
+ url = "https://www.baidu.com"
23
+ http_result = 'null'
24
+ try:
25
+ # 发送 HTTP 请求
26
+ response = requests.get(url)
27
+
28
+ # 检查响应状态码
29
+ if response.status_code == 200:
30
+ http_result = f"成功连接到网页: {url}"
31
+ else:
32
+ http_result = f"无法连接到网页,状态码: {response.status_code}"
33
+ except requests.exceptions.RequestException as e:
34
+ http_result = f"连接失败: {e}"
35
+
36
+ return {"output": http_result}
37
 
38
  app.mount("/", StaticFiles(directory="static", html=True), name="static")
39