-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
51 lines (34 loc) · 1.28 KB
/
app.py
File metadata and controls
51 lines (34 loc) · 1.28 KB
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
43
44
45
46
47
48
49
50
51
from fastapi import FastAPI, UploadFile, File
from fastapi.responses import HTMLResponse
from claude_service import generate_image_description
app = FastAPI()
@app.get("/", response_class=HTMLResponse)
def home():
return """
<html>
<body>
<h2>WCAG Image Description Generator</h2>
<input type="file" id="image"/>
<button onclick="generate()">Generate Description</button>
<p id="result"></p>
<script>
async function generate(){
let file = document.getElementById("image").files[0]
let formData = new FormData()
formData.append("file", file)
let response = await fetch("/generate", {
method: "POST",
body: formData
})
let data = await response.json()
document.getElementById("result").innerText = data.description
}
</script>
</body>
</html>
"""
@app.post("/generate")
async def generate(file: UploadFile = File(...)):
image_bytes = await file.read()
description = generate_image_description(image_bytes, file.content_type)
return {"description": description}