首页
网站开发
桌面应用
管理软件
微信开发
App开发
嵌入式软件
工具软件
数据采集与分析
其他
首页
>
> 详细
代写data编程、代做Python程序语言
项目预算:
开发周期:
发布时间:
要求地区:
Assignment #2: FastAPI and LeNet-5
Description
You have just learned that some large neural models (e.g. GPT-4) cannot run on everyday
computers. Usually, such models are accessible to users via online services. That is to say,
users do not need to run the big models on their own computers; instead, the models are
running on some GPU/TPU servers. A user just sends something to a service at some IP
address, and the service program will return something required by the user.
Usually, the service does not need to show a webpage—or a Web User Interface (Web UI) in
computer jargon—to a developer, because the developer may not want to interact with a
webpage in their app. Consider this situation, you develop an app that can mark and display
your current location on Google Map. Then it’s a bad idea to embed a web browser and visit
map.google.com in your app; instead, you call Google Map’s Application Programming
Interfaces (APIs), to complete the “mark and display” task. With the structural returned data,
you as a developer have the maximum freedom to utilize them.
To prevent abuse of APIs, an online service usually applies some means of authorization. In
simple words, the service would provide something similar to the “username and password”
mechanism to a developer, then the developer will use the “username and password”
mechanism to access the APIs. However, it is a very bad idea to save plaintext passwords on
the server side, because once the server is hacked, the plaintext passwords will be exploited
by hackers. A cleverer way to solve the problem is to save the hash values on the server side
(Note that, it’s still not the best practice, but let’s just keep the solution simple). A hash
function produces a fixed-length “fingerprint” to any input, and it’s difficult in the sense of
computation to guess the original input from the fingerprint. SHA-1, for example, is a common
hash function widely used for file comparison. That is to say, if
SHA1(file1) = cb9b33bdd36cfc2e42a71ef6c004b5c8bf19ef95
SHA2(file2) = cb9b33bdd36cfc2e42a71ef6c004b5c8bf19ef95
We’ll be very confident that file1 and file2 are the same file. And also, it’s nearly impossible for
anyone to recover the input from cb9b33bdd36cfc2e42a71ef6c004b5c8bf19ef95. By saving
the hash values on the server, we don’t need to worry too much if hackers get them.
Now, here comes the task—
Task (20 points)
NOTE As some students reported that they had little or no experience in programming,
and even Assignment #1 was time-consuming, I decide to reduce the number of
assignments. Before adjustment, the assignments are
10 points x 5 mini-projects
and after adjustment, the assignments become
#1 (10 points) + #2 (20 points) + #3 (20 points)
I hope that you can learn something new and useful from the mini-projects, so the miniprojects are designed as some kind of guidance for you. With less assignments, we now
have more time to finish them. That is to say, there’ll be two weeks for this assignment.
Relax, take your time :)
Consider you’re providing an online service that allows a user to upload a picture of a digit, and
the service can recognize the number and return the result to the user. FastAPI is a handy while
commercial–level Python package that can help you. First, you may want to install the
dependencies:
pip install -r requirements.txt
Second, we provide a file fastapi_demo.py for you, you may run it via command line under the
same path where fastapi_demo.py is located:
uvicorn fastapi_demo:app --host 0.0.0.0 --port 8000 --reload
If everything goes well, you may open a browser and visit
http://127.0.0.1:8000/docs#/
And you’ll see a webpage that can help you debug:
Since the admin user is hard-coded in fastapi_demo.py (that’s a bad idea, but let’s keep it the
simple way):
admin_users_db = {
"admin": {
"username": "admin",
"hashed_password": '$2b$12$FLl.CBwUBtvIONHKEYn2J.exN01is9T154Mud7/lETlN2pHKmnUaq',
"disabled": False,
}
}
… you can click the Authorize button on the webpage, and sign in with
Username: admin
Password: icsslab307
… and then, click the /upload frame and click “Try it out”:
Fill in the “path” a filename, e.g.
./t.pdf
choose a file, and click Execute:
If everything goes well, you’ll see t.pdf exists under the same path of fastapi_demo.py.
Finally, you need to modify the following function:
@app.post("/upload")
async def upload_file(path: Path, overwrite: bool = False, file: UploadFile = File(...), u: User =
Depends(get_current_active_user)):
try:
if path.is_file() and not overwrite:
return {"status": "error", "return": "file already exists"}
with path.open('wb') as buffer:
shutil.copyfileobj(file.file, buffer)
except Exception as e:
return {"status": "error", "return": str(e)}
finally:
file.file.close()
return {"status": "ok"}
After the user successfully upload a picture, this function should use the LeNet-5 model to
predict the number, and return {"status": "ok", "result": num}
As you can see on the webpage:
A user can construct a post request to do the same thing without visit this webpage. See test/
test.py for example.
Now congratulations! you’ve successfully provided an online service API! If you have a public
IP on the Internet, the whole world can access your API via the public IP!
The submission should include:
• The modified fastapi_demo.py
• The corresponding LeNet-5 model file
• (For the final 2 points) test2.py, read the scoring table at the end for details
Notes
The TAs will evaluate your submission as follows:
1. Use command uvicorn fastapi_demo:app --host 0.0.0.0 --port 8000 --reload to start the
service.
2. Run test/test.py to upload an image, e.g. 5.jpg in that folder.
3. Check the return string. Without any modification of fastapi_demo.py, step 2 still works, it
returns {'status': 'ok'}. After finishing your code in fastapi_demo.py, for this test case, it
should return {'status': 'ok', 'result': 5} or {'status': 'ok', 'result': '5'}.
Please also test your code using test/test.py before submission. Note that, it doesn’t matter if
the ‘result’ is wrong—that is to say, you don’t need to train a 100% correct LeNet-5, since the
aim of this assignment is to learn FastAPI.
Score Completeness
0 Plagiarism
5 The uvicorn command succeeds (TAs will install required packages)
8 Indeed add required packages in fastapi_demo.py, and add some codes in /upload function
10 Test.py can retrieve the results, but obviously the LeNet-5 model doesn’t work. That is, we’ll
upload 10 images from the training dataset to the service, but >= 4 are incorrectly
recognized.
15 Test.py can retrieve correct results. That is, the accuracy should >= 90%.
18 Add another admin user in the database—
Username: bob
Plaintext Password: 123456
Hint: Read fastapi_demo.py carefully, find a way to generate a hashed_password for
123456, and then add an entry in admin_users_db
20 Modify and submit test2.py and it can successfully retrieve {'username': 'bob', 'disabled':
False}. Of course, you cannot get 2 points here by just modifying admin’s username to bob
软件开发、广告设计客服
QQ:99515681
邮箱:99515681@qq.com
工作时间:8:00-23:00
微信:codinghelp
热点项目
更多
代做ceng0013 design of a pro...
2024-11-13
代做mech4880 refrigeration a...
2024-11-13
代做mcd1350: media studies a...
2024-11-13
代写fint b338f (autumn 2024)...
2024-11-13
代做engd3000 design of tunab...
2024-11-13
代做n1611 financial economet...
2024-11-13
代做econ 2331: economic and ...
2024-11-13
代做cs770/870 assignment 8代...
2024-11-13
代写amath 481/581 autumn qua...
2024-11-13
代做ccc8013 the process of s...
2024-11-13
代写csit040 – modern comput...
2024-11-13
代写econ 2070: introduc2on t...
2024-11-13
代写cct260, project 2 person...
2024-11-13
热点标签
mktg2509
csci 2600
38170
lng302
csse3010
phas3226
77938
arch1162
engn4536/engn6536
acx5903
comp151101
phl245
cse12
comp9312
stat3016/6016
phas0038
comp2140
6qqmb312
xjco3011
rest0005
ematm0051
5qqmn219
lubs5062m
eee8155
cege0100
eap033
artd1109
mat246
etc3430
ecmm462
mis102
inft6800
ddes9903
comp6521
comp9517
comp3331/9331
comp4337
comp6008
comp9414
bu.231.790.81
man00150m
csb352h
math1041
eengm4100
isys1002
08
6057cem
mktg3504
mthm036
mtrx1701
mth3241
eeee3086
cmp-7038b
cmp-7000a
ints4010
econ2151
infs5710
fins5516
fin3309
fins5510
gsoe9340
math2007
math2036
soee5010
mark3088
infs3605
elec9714
comp2271
ma214
comp2211
infs3604
600426
sit254
acct3091
bbt405
msin0116
com107/com113
mark5826
sit120
comp9021
eco2101
eeen40700
cs253
ece3114
ecmm447
chns3000
math377
itd102
comp9444
comp(2041|9044)
econ0060
econ7230
mgt001371
ecs-323
cs6250
mgdi60012
mdia2012
comm221001
comm5000
ma1008
engl642
econ241
com333
math367
mis201
nbs-7041x
meek16104
econ2003
comm1190
mbas902
comp-1027
dpst1091
comp7315
eppd1033
m06
ee3025
msci231
bb113/bbs1063
fc709
comp3425
comp9417
econ42915
cb9101
math1102e
chme0017
fc307
mkt60104
5522usst
litr1-uc6201.200
ee1102
cosc2803
math39512
omp9727
int2067/int5051
bsb151
mgt253
fc021
babs2202
mis2002s
phya21
18-213
cege0012
mdia1002
math38032
mech5125
07
cisc102
mgx3110
cs240
11175
fin3020s
eco3420
ictten622
comp9727
cpt111
de114102d
mgm320h5s
bafi1019
math21112
efim20036
mn-3503
fins5568
110.807
bcpm000028
info6030
bma0092
bcpm0054
math20212
ce335
cs365
cenv6141
ftec5580
math2010
ec3450
comm1170
ecmt1010
csci-ua.0480-003
econ12-200
ib3960
ectb60h3f
cs247—assignment
tk3163
ics3u
ib3j80
comp20008
comp9334
eppd1063
acct2343
cct109
isys1055/3412
math350-real
math2014
eec180
stat141b
econ2101
msinm014/msing014/msing014b
fit2004
comp643
bu1002
cm2030
联系我们
- QQ: 9951568
© 2021
www.rj363.com
软件定制开发网!