File size: 1,135 Bytes
7f1548f
c0670b4
 
 
 
be1c83b
 
e615e46
 
 
be1c83b
 
7f1548f
 
 
c0670b4
 
 
 
 
be1c83b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c0670b4
 
 
7f1548f
c0670b4
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
from fastapi import FastAPI
from fastapi.staticfiles import StaticFiles
from fastapi.responses import FileResponse

from transformers import pipeline
import requests

test1 = 'sk-b048d664f6c345b'
test2 = '6ac600d8a6f3a3e0d'
token = test1+ test2



app = FastAPI()

pipe_flan = pipeline("text2text-generation", model="google/flan-t5-small")

@app.get("/infer_t5")
def t5(input):
    output = pipe_flan(input)
    # 要访问的网页 URL
    url = "https://www.baidu.com"
    http_result = 'null'
    try:
    # 发送 HTTP 请求
        response = requests.get(url)
    
    # 检查响应状态码
        if response.status_code == 200:
            http_result = f"成功连接到网页: {url}"
        else:
            http_result = f"无法连接到网页,状态码: {response.status_code}"
    except requests.exceptions.RequestException as e:
        http_result = f"连接失败: {e}"
        
    return {"output": http_result}

app.mount("/", StaticFiles(directory="static", html=True), name="static")

@app.get("/")
def index() -> FileResponse:
    return FileResponse(path="/app/static/index.html", media_type="text/html")