Week 5 Class1
Android App1 Using ChatGPT API
Let's build OCR + ChatGPT API App
My team won $350 for a hackathon at HackEmory
Topics for Today
1. What is REST API & SERVER -> done
2. Setting up ChatGPT API and tutorial -> done
3. Python intro + API setup -> done
4. Flask RestAPI Setup -> done
6. Hosting on Cloud (Azure)
Camera setup
5. Retrofit Android ->
later week 6 next app +
. Async vs Sync Operations :
7. Coroutines
Live Demo first
Remember we have bounty program fix bug and get Rs. 1000 ($15)
Problems
1. Documentation are not the best
Java -> Kotlin (digitalocean, medium, stackoverflow)
2. You have to go on StackOverflow
3. Don't be shy to ask
4. Ask ChatGPT
What is a server?
Any computer giving services with other computers!
Sharing is caring
REST API
A REST API (Representational State Transfer Application Programming Interface) is a set of rules and conventions for building and interacting with web services.
CRUD Operations
Create: Post
Read: Get
Update: Put
Delete: Delete
Client Server errors
200 -> Success
400s -> Client Side error
500 -> Server Side error
Python 3 Flask Server
Google OCR Kit:
https://developers.google.com/ml-kit/vision/text-recognition/v2/android
Try to integrate
if Stuck you have:
1. ChatGPT
2. Google Dcoumentationa
3. Stack overflow
4. Discord community
IaaS vs PaaS vs SaaS

Gmail
App -> Facebook
I think in most clouds:
IAAS -> gives you a machine(VM/server) with a OS at minimum
PaaS-> service gives you IaaS + a runtime environment to host your apps in
SaaS->gives you IaaS+PaaS+finished app
Elastic Search
IND / CHINA / USA
Default ->

IaaS
Azure / GcP/ AWS Vms
Manage your server on your own on someone else computer
PaaS
AWS Lamda + Azure App Service + Google App Engine
Give a Python file it will do the magic
SaaS -> ready made apps
like Play store apps
Apache -> Web server
Conductor that allows you to host server on a web app and manage the traffic
load balancing
Reverse Proxy

Conductor for trains
80 / 443
maps. google
madeby.google
images..google
same port for all
before server so called reverse proxy
Proxy example
banned websites
Load Balance vs Reverse Proxy
Load balancer on a different server to manage load between severs
but Reverse Proxy is part of 1 Server
Nginx setup
apt-get install nginx
nano /etc/nginx/nginx.conf
Retstart ->sudo nginx -s reload
systemctl reload nginx
https://www.digitalocean.com/community/tutorials/how-to-install-nginx-on-ubuntu-20-04
nginx conf file
Text

My Nginx file
events {
worker_connections 1024;
}
http{
server {
listen 80;
server_name chatgptvm2.eastus.cloudapp.azure.com;
# access_log /var/log/nginx/access.log;
# error_log /var/log/nginx/error.log;
location / {
proxy_pass http://127.0.0.1:5000/;
proxy_set_header Host $host;
# proxy_set_header X-Real-IP $remote_addr;
# proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
#proxy_set_header X-Forwarded-Proto $scheme;
}
}
}
Reverse Proxy
run htop or acivity manager
You are not using complete CPU power
Run Multiple processes in one server
Steps to deploy
1. Create VM
2. Open the right ports on Azure or any cloud (80 / 443)
3. copy code python3 code of flask server
4. Make sure it never turns off -> docker / pm2
5. Ngnix / Apache2 for reverse proxy
Network capture via wifi router
Cert Management
without cert on port 80

Make encrypted using TLS cert
cert installation steps:
https://certbot.eff.org/instructions?ws=nginx&os=ubuntufocal
Week 5 ChatGPT Api + Retrofit + Python server
By Harnoor Singh
Week 5 ChatGPT Api + Retrofit + Python server
- 408