Spaces:
Running
Running
update main
Browse files
main.py
CHANGED
|
@@ -9,6 +9,7 @@ import io
|
|
| 9 |
import base64
|
| 10 |
import matplotlib.pyplot as plt
|
| 11 |
import torch
|
|
|
|
| 12 |
from transformers import pipeline,VisionEncoderDecoderModel,ViTImageProcessor,AutoTokenizer
|
| 13 |
from transformers import BartForConditionalGeneration, BartTokenizer
|
| 14 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
|
@@ -92,7 +93,17 @@ def index(req:Request):
|
|
| 92 |
def index(req:Request):
|
| 93 |
return templates.TemplateResponse('ImageInterpretation.html',{'request':req})
|
| 94 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 95 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 96 |
|
| 97 |
@app.post("/caption")
|
| 98 |
def caption(file:UploadFile=File(...)):
|
|
@@ -122,8 +133,6 @@ def summerzation(file:UploadFile=File(...)):
|
|
| 122 |
text = get_text_from_EXCEL(file.file)
|
| 123 |
else:
|
| 124 |
return {"error": "Unsupported file type"}
|
| 125 |
-
if not text.strip():
|
| 126 |
-
return {"error": "File is empty"}
|
| 127 |
|
| 128 |
result=""
|
| 129 |
for i in range(0,len(text),1024):
|
|
|
|
| 9 |
import base64
|
| 10 |
import matplotlib.pyplot as plt
|
| 11 |
import torch
|
| 12 |
+
import tensorflow
|
| 13 |
from transformers import pipeline,VisionEncoderDecoderModel,ViTImageProcessor,AutoTokenizer
|
| 14 |
from transformers import BartForConditionalGeneration, BartTokenizer
|
| 15 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
|
|
|
| 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 |
|
| 108 |
@app.post("/caption")
|
| 109 |
def caption(file:UploadFile=File(...)):
|
|
|
|
| 133 |
text = get_text_from_EXCEL(file.file)
|
| 134 |
else:
|
| 135 |
return {"error": "Unsupported file type"}
|
|
|
|
|
|
|
| 136 |
|
| 137 |
result=""
|
| 138 |
for i in range(0,len(text),1024):
|