Download main.py from YSXysx/MyFirstTestCreat_Google_T5: direct link, hf CLI and curl.
- Browser
- Download file 1.14 kB
-
https://huggingface.co/spaces/YSXysx/MyFirstTestCreat_Google_T5/resolve/main/main.py
- Command line
-
hf download hf://spaces/YSXysx/MyFirstTestCreat_Google_T5/main.py
-
curl -L -o main.py https://huggingface.co/spaces/YSXysx/MyFirstTestCreat_Google_T5/resolve/main/main.py
1.14 kB
| 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") | |
| 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") | |
| def index() -> FileResponse: | |
| return FileResponse(path="/app/static/index.html", media_type="text/html") |