File size: 1,146 Bytes
1aaf5de
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from fastapi import FastAPI
from fastapi.responses import HTMLResponse
from pydantic import BaseModel
import uvicorn

app = FastAPI(title="Docker0 测试应用")

class TextInput(BaseModel):
    text: str

@app.get("/", response_class=HTMLResponse)
async def home():
    return """
    <html>
        <head><title>Docker0 Space</title></head>
        <body style="font-family: Arial; text-align: center; padding-top: 100px;">
            <h1>🐳 Docker0 Space 测试成功!</h1>
            <p>这是一个运行在 Hugging Face Docker Space 上的 FastAPI 应用。</p>
            <p>试试访问:<a href="/generate?text=你好,世界">/generate?text=你好,世界</a></p>
            <p>当前时间:2026 年测试环境</p>
        </body>
    </html>
    """

@app.get("/generate")
async def generate(text: str = "默认测试文本"):
    result = f"收到输入:{text}\n\n处理结果:这是一个来自 Docker Space 的测试回复!🚀"
    return {"input": text, "output": result, "status": "success"}

# 如果直接运行(本地测试用)
if __name__ == "__main__":
    uvicorn.run(app, host="0.0.0.0", port=7860)