![](/img/trans.png)
[英]Enthought Canopy 1.1 giving error icui18n: cannot open shared object file: No such file or directory
[英]Flask Api with HTML giving Runtime error: cannot open image_file: No such file or directory
我正在使用帶有 html ui 文件的基於燒瓶的 api。 當我嘗試通過 html 上傳 pdf 並且它通過我的 api.py 文件時,它給出了不存在這樣的文件的運行時錯誤。
app.py File
app = Flask(__name__)
@app.route('/predict', methods=['GET', 'POST'])
def predict():
if request.method == 'POST':
image_file = request.files["file_image"]
print(image_file)
nlp_model = spacy.load("nlp_model")
docs = fitz.open(image_file)
text = ""
for p in docs:
text = text + str(p.getText())
tx_2 = "".join(text.split('\n'))
doc = nlp_model(tx_2)
s = []
for ent in doc.ents:
s.append(ent)
return s
if __name__ == '__main__':
app.run()
HTML文件
<!doctype html>
<title>Upload new File</title>
<h1>Upload new File</h1>
<form action="/predict" method="POST" enctype=multipart/form-data>
<input type=file name="file_image">
<input type=submit value=Submit>
</form>
表格
<form action="/predict">
將數據發送到
@app.route('/predict')
你想要其中之一
<form action="/index">
<form action="{{ url_for('predict') }}">
編輯:我不確定fitz.open()
做了什么,但您將字符串'image_file'
傳遞給它。 不是實際的文件名,應該是fitz.open(image_file.filename)
此外,您可能需要在將文件名傳遞給 fitz 之前將文件保存到磁盤,但同樣,我不知道此模塊是否需要這樣做。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.