Initial commit
Browse files- .bolt/config.json +3 -0
- .gitignore +1 -0
- Dockerfile +10 -0
- app.py +29 -0
- index.js +3 -0
- package-lock.json +10 -0
- package.json +7 -0
- requirements.txt +6 -0
.bolt/config.json
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"template": "node"
|
3 |
+
}
|
.gitignore
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
node_modules
|
Dockerfile
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
FROM python:3.9-slim
|
2 |
+
|
3 |
+
WORKDIR /code
|
4 |
+
|
5 |
+
COPY requirements.txt .
|
6 |
+
RUN pip install --no-cache-dir -r requirements.txt
|
7 |
+
|
8 |
+
COPY . .
|
9 |
+
|
10 |
+
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
|
app.py
ADDED
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from fastapi import FastAPI
|
2 |
+
from transformers import AutoProcessor, AutoModelForVisualQuestionAnswering
|
3 |
+
from pydantic import BaseModel
|
4 |
+
import torch
|
5 |
+
|
6 |
+
app = FastAPI()
|
7 |
+
|
8 |
+
# Load model and processor
|
9 |
+
processor = AutoProcessor.from_pretrained("microsoft/OmniParser")
|
10 |
+
model = AutoModelForVisualQuestionAnswering.from_pretrained("microsoft/OmniParser")
|
11 |
+
|
12 |
+
class Query(BaseModel):
|
13 |
+
image_url: str
|
14 |
+
question: str
|
15 |
+
|
16 |
+
@app.post("/predict")
|
17 |
+
async def predict(query: Query):
|
18 |
+
# Process the image and question
|
19 |
+
inputs = processor(images=query.image_url, text=query.question, return_tensors="pt")
|
20 |
+
outputs = model(**inputs)
|
21 |
+
|
22 |
+
# Get the predicted answer
|
23 |
+
predicted_answer = processor.decode(outputs.logits.argmax(-1)[0], skip_special_tokens=True)
|
24 |
+
|
25 |
+
return {"answer": predicted_answer}
|
26 |
+
|
27 |
+
@app.get("/")
|
28 |
+
async def root():
|
29 |
+
return {"message": "OmniParser API is running. Use /predict endpoint for predictions."}
|
index.js
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
// run `node index.js` in the terminal
|
2 |
+
|
3 |
+
console.log(`Hello Node.js v${process.versions.node}!`);
|
package-lock.json
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"name": "node-starter",
|
3 |
+
"lockfileVersion": 3,
|
4 |
+
"requires": true,
|
5 |
+
"packages": {
|
6 |
+
"": {
|
7 |
+
"name": "node-starter"
|
8 |
+
}
|
9 |
+
}
|
10 |
+
}
|
package.json
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"name": "node-starter",
|
3 |
+
"private": true,
|
4 |
+
"scripts": {
|
5 |
+
"test": "echo \"Error: no test specified\" && exit 1"
|
6 |
+
}
|
7 |
+
}
|
requirements.txt
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
fastapi==0.68.0
|
2 |
+
uvicorn==0.15.0
|
3 |
+
torch==2.0.0
|
4 |
+
transformers
|
5 |
+
pydantic
|
6 |
+
python-multipart
|