Spaces:
Running
Running
change in main
Browse files
main.py
CHANGED
|
@@ -33,10 +33,10 @@ app.add_middleware(
|
|
| 33 |
allow_headers=["*"],
|
| 34 |
)
|
| 35 |
try:
|
| 36 |
-
|
| 37 |
-
interpreter_model = VisionEncoderDecoderModel.from_pretrained("nlpconnect/vit-gpt2-image-captioning")
|
| 38 |
-
interpreter_processor = ViTImageProcessor.from_pretrained("nlpconnect/vit-gpt2-image-captioning")
|
| 39 |
-
interpreter_tokenizer = AutoTokenizer.from_pretrained("nlpconnect/vit-gpt2-image-captioning")
|
| 40 |
except Exception as exp:
|
| 41 |
print("[ERROR] Can't load nlpconnect/vit-gpt2-image-captioning")
|
| 42 |
print(str(exp))
|
|
@@ -59,21 +59,21 @@ except Exception as exp:
|
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
-
#try:
|
| 63 |
-
# generator = pipeline("text-generation", model="deepseek-ai/deepseek-coder-1.3b-instruct", device_map="auto")
|
| 64 |
-
#except Exception as exp:
|
| 65 |
-
# print("[ERROR] Can't load deepseek-ai/deepseek-coder-1.3b-instruct ")
|
| 66 |
-
# print(str(exp))
|
| 67 |
-
|
| 68 |
-
|
| 69 |
try:
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
except Exception as exp :
|
| 73 |
print("[ERROR] Can't load deepseek-ai/deepseek-coder-1.3b-instruct ")
|
| 74 |
print(str(exp))
|
| 75 |
|
| 76 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
app.mount("/static",StaticFiles(directory='static'),'static')
|
| 78 |
templates = Jinja2Templates(directory='templates')
|
| 79 |
|
|
@@ -99,12 +99,12 @@ def caption(file:UploadFile=File(...)):
|
|
| 99 |
if extension not in Supported_extensions:
|
| 100 |
return {"error": "Unsupported file type"}
|
| 101 |
image = Image.open(file.file)
|
| 102 |
-
|
| 103 |
-
pixel_values = interpreter_processor(images=image, return_tensors="pt").pixel_values
|
| 104 |
-
output_ids = interpreter_model.generate(pixel_values, max_length=16, num_beams=4)
|
| 105 |
-
caption = interpreter_tokenizer.decode(output_ids[0], skip_special_tokens=True)
|
| 106 |
-
return {"caption":caption}
|
| 107 |
-
|
| 108 |
|
| 109 |
@app.post("/summerize")
|
| 110 |
def summerzation(file:UploadFile=File(...)):
|
|
@@ -124,8 +124,8 @@ def summerzation(file:UploadFile=File(...)):
|
|
| 124 |
return {"error": "File is empty"}
|
| 125 |
|
| 126 |
result=""
|
| 127 |
-
|
| 128 |
-
|
| 129 |
return {"summary": result}
|
| 130 |
|
| 131 |
|
|
@@ -164,7 +164,7 @@ error.
|
|
| 164 |
##Prompt: {prompt}.
|
| 165 |
"""
|
| 166 |
|
| 167 |
-
output =
|
| 168 |
match = re.search(r'```python(.*?)```', output[0]["generated_text"], re.DOTALL)
|
| 169 |
code =''
|
| 170 |
if not match:
|
|
|
|
| 33 |
allow_headers=["*"],
|
| 34 |
)
|
| 35 |
try:
|
| 36 |
+
interpreter = pipeline("image-to-text", model="nlpconnect/vit-gpt2-image-captioning")
|
| 37 |
+
#interpreter_model = VisionEncoderDecoderModel.from_pretrained("nlpconnect/vit-gpt2-image-captioning")
|
| 38 |
+
#interpreter_processor = ViTImageProcessor.from_pretrained("nlpconnect/vit-gpt2-image-captioning")
|
| 39 |
+
#interpreter_tokenizer = AutoTokenizer.from_pretrained("nlpconnect/vit-gpt2-image-captioning")
|
| 40 |
except Exception as exp:
|
| 41 |
print("[ERROR] Can't load nlpconnect/vit-gpt2-image-captioning")
|
| 42 |
print(str(exp))
|
|
|
|
| 59 |
|
| 60 |
|
| 61 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
try:
|
| 63 |
+
generator = pipeline("text-generation", model="deepseek-ai/deepseek-coder-1.3b-instruct", device_map="auto")
|
| 64 |
+
except Exception as exp:
|
|
|
|
| 65 |
print("[ERROR] Can't load deepseek-ai/deepseek-coder-1.3b-instruct ")
|
| 66 |
print(str(exp))
|
| 67 |
|
| 68 |
|
| 69 |
+
#try:
|
| 70 |
+
# generator_model = AutoModelForCausalLM.from_pretrained("deepseek-ai/deepseek-coder-1.3b-instruct", trust_remote_code=True)
|
| 71 |
+
# tokengenerator_modelizer = AutoTokenizer.from_pretrained("deepseek-ai/deepseek-coder-1.3b-instruct", trust_remote_code=True)
|
| 72 |
+
#except Exception as exp :
|
| 73 |
+
# print("[ERROR] Can't load deepseek-ai/deepseek-coder-1.3b-instruct ")
|
| 74 |
+
# print(str(exp))
|
| 75 |
+
|
| 76 |
+
|
| 77 |
app.mount("/static",StaticFiles(directory='static'),'static')
|
| 78 |
templates = Jinja2Templates(directory='templates')
|
| 79 |
|
|
|
|
| 99 |
if extension not in Supported_extensions:
|
| 100 |
return {"error": "Unsupported file type"}
|
| 101 |
image = Image.open(file.file)
|
| 102 |
+
caption = interpreter(image)
|
| 103 |
+
#pixel_values = interpreter_processor(images=image, return_tensors="pt").pixel_values
|
| 104 |
+
#output_ids = interpreter_model.generate(pixel_values, max_length=16, num_beams=4)
|
| 105 |
+
#caption = interpreter_tokenizer.decode(output_ids[0], skip_special_tokens=True)
|
| 106 |
+
#return {"caption":caption}
|
| 107 |
+
return {"caption": caption[0]['generated_text']}
|
| 108 |
|
| 109 |
@app.post("/summerize")
|
| 110 |
def summerzation(file:UploadFile=File(...)):
|
|
|
|
| 124 |
return {"error": "File is empty"}
|
| 125 |
|
| 126 |
result=""
|
| 127 |
+
for i in range(0,len(text),1024):
|
| 128 |
+
result+=summarizer(text, max_length=150, min_length=30, do_sample=False)[0]['summary_text']
|
| 129 |
return {"summary": result}
|
| 130 |
|
| 131 |
|
|
|
|
| 164 |
##Prompt: {prompt}.
|
| 165 |
"""
|
| 166 |
|
| 167 |
+
output = generator(message, max_length=1000)
|
| 168 |
match = re.search(r'```python(.*?)```', output[0]["generated_text"], re.DOTALL)
|
| 169 |
code =''
|
| 170 |
if not match:
|