Spaces:
Running
Running
update main
Browse files
main.py
CHANGED
|
@@ -36,10 +36,10 @@ app.add_middleware(
|
|
| 36 |
|
| 37 |
from transformers import VisionEncoderDecoderModel, ViTImageProcessor, AutoTokenizer
|
| 38 |
try:
|
| 39 |
-
interpreter =
|
| 40 |
-
interpreter_model = VisionEncoderDecoderModel.from_pretrained("nlpconnect/vit-gpt2-image-captioning")
|
| 41 |
-
interpreter_processor = ViTImageProcessor.from_pretrained("nlpconnect/vit-gpt2-image-captioning")
|
| 42 |
-
interpreter_tokenizer = AutoTokenizer.from_pretrained("nlpconnect/vit-gpt2-image-captioning")
|
| 43 |
except Exception as exp:
|
| 44 |
print("[ERROR] Can't load nlpconnect/vit-gpt2-image-captioning")
|
| 45 |
print(str(exp))
|
|
@@ -63,7 +63,7 @@ except Exception as exp:
|
|
| 63 |
|
| 64 |
|
| 65 |
try:
|
| 66 |
-
generator = pipeline("text-generation", model="deepseek-ai/deepseek-coder-1.3b-instruct"
|
| 67 |
except Exception as exp:
|
| 68 |
print("[ERROR] Can't load deepseek-ai/deepseek-coder-1.3b-instruct ")
|
| 69 |
print(str(exp))
|
|
@@ -93,17 +93,7 @@ def index(req:Request):
|
|
| 93 |
def index(req:Request):
|
| 94 |
return templates.TemplateResponse('ImageInterpretation.html',{'request':req})
|
| 95 |
|
| 96 |
-
@app.post("/caption2")
|
| 97 |
-
async def generate_caption(file: UploadFile = File(...)):
|
| 98 |
-
contents = await file.read()
|
| 99 |
-
image = Image.open(io.BytesIO(contents)).convert("RGB")
|
| 100 |
|
| 101 |
-
# توليد caption
|
| 102 |
-
pixel_values = interpreter_processor(images=image, return_tensors="pt").pixel_values
|
| 103 |
-
output_ids = interpreter_model.generate(pixel_values, max_length=16, num_beams=4)
|
| 104 |
-
caption = interpreter_tokenizer.decode(output_ids[0], skip_special_tokens=True)
|
| 105 |
-
|
| 106 |
-
return {"caption": caption}
|
| 107 |
@app.post('/get')
|
| 108 |
def g(f:str):
|
| 109 |
return generator(f)[0]["generated_text"]
|
|
|
|
| 36 |
|
| 37 |
from transformers import VisionEncoderDecoderModel, ViTImageProcessor, AutoTokenizer
|
| 38 |
try:
|
| 39 |
+
interpreter =pipeline("image-to-text", model="Salesforce/blip-image-captioning-base")
|
| 40 |
+
#interpreter_model = VisionEncoderDecoderModel.from_pretrained("nlpconnect/vit-gpt2-image-captioning")
|
| 41 |
+
#interpreter_processor = ViTImageProcessor.from_pretrained("nlpconnect/vit-gpt2-image-captioning")
|
| 42 |
+
#interpreter_tokenizer = AutoTokenizer.from_pretrained("nlpconnect/vit-gpt2-image-captioning")
|
| 43 |
except Exception as exp:
|
| 44 |
print("[ERROR] Can't load nlpconnect/vit-gpt2-image-captioning")
|
| 45 |
print(str(exp))
|
|
|
|
| 63 |
|
| 64 |
|
| 65 |
try:
|
| 66 |
+
generator = pipeline("text-generation", model="deepseek-ai/deepseek-coder-1.3b-instruct")
|
| 67 |
except Exception as exp:
|
| 68 |
print("[ERROR] Can't load deepseek-ai/deepseek-coder-1.3b-instruct ")
|
| 69 |
print(str(exp))
|
|
|
|
| 93 |
def index(req:Request):
|
| 94 |
return templates.TemplateResponse('ImageInterpretation.html',{'request':req})
|
| 95 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 96 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 97 |
@app.post('/get')
|
| 98 |
def g(f:str):
|
| 99 |
return generator(f)[0]["generated_text"]
|