Dùng git bash, nhập lệnh:
$ git clone https://github.com/tvdeev206/FastAPIProject.git
$ cd FastAPIProject
Dùng python terminal, nhập lệnh:
$ python -m venv venv
$ venv\Scripts\activate
Dùng python terminal, nhập lệnh:
$ pip install -r requirements.txt
Dùng python terminal, nhập lệnh:
$ uvicorn main:app --reload
Khi này trên terminal sẽ thông báo:
INFO: Will watch for changes in these directories: ['C:\\Users\\Windows\\PycharmProjects\\FastAPIProject']
INFO: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
INFO: Started reloader process [28432] using WatchFiles
Tức là Server đã được khởi tạo và được host ở http://127.0.0.1:8000.
Khi này ta có thể copy URL và paste lên web hoặc ấn vào link URL.
Nhưng khi này ta chưa gửi request nên sẽ web sẽ không load được.
Mở thêm một terminal và nhập lệnh:
$ python test_get.py
hoặc
$ python test_gethealth.py
hoặc
$ python prompt.py
Với test_get.py file, thì ở trên web và terminal sẽ hiện một đoạn giới thiệu về mô hình, chức năng của mô hình và kiến trúc của hệ thống.
Với test_gethealth.py file, thì ở terminal sẽ hiện ra tình trạng của hệ thống ở dạng JSON
{'status': 'ok'}
Với prompt.py file, thì terminal sẽ cần cung cấp input đầu vào là "prompt" và "role", khi này ta cần nhập dữ liệu đầu vào, sau đó thì terminal sẽ hiện ra output là văn bản dựa trên input đầu vào, ví dụ:
Dữ liệu đầu vào:
$ Enter a prompt: Explain Machine learning
$ Enter a role: As an expert in Computer Science
Dữ liệu ra:
{'prompt': [{'role': 'As an expert in Computer Science', 'content': 'Explain Machine learning'}], 'generated_text': 'Machine learning is a subset of artificial intelligence that focuses on enabling computers to learn from data without being ex
plicitly programmed. Instead of following a strict set of rules, machine learning algorithms analyze patterns in large datasets to make predictions or decisions. \n\nThe process typically involves three stages: \n1. **Data Collection** – Gat
hering relevant information from sources like sensors, websites, or databases. \n2. **Feature Extraction** – Identifying the most important features or variables that contribute to the outcome. \n3. **Model Training** – Using the extracted f
eatures to train a statistical model, which learns from the data to improve its accuracy over time. \n\nMachine learning excels in scenarios where data is abundant and complex, such as image recognition, natural language processing, recommend
ation systems, and predictive analytics. It is widely applied in industries like healthcare, finance, marketing, and autonomous vehicles, where the ability to adapt and improve continuously is critical. \n\nWould you like me to also explain **how'}
Tại python terminal, nhập lệnh:
$ pip install "fastapi[standard]"
Sau đó, nhập lệnh:
$ fastapi dev
Khi này ở terminal sẽ xuất hiện
╭────────── FastAPI CLI - Development mode ───────────╮
│ │
│ Serving at: http://127.0.0.1:8000 │
│ │
│ API docs: http://127.0.0.1:8000/docs │
│ │
│ Running in development mode, for production use: │
│ │
│ fastapi run │
│ │
╰─────────────────────────────────────────────────────╯
INFO: Will watch for changes in these directories: ['/home/user/code/awesomeapp']
INFO: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
INFO: Started reloader process [2248755] using WatchFiles
INFO: Started server process [2248757]
INFO: Waiting for application startup.
INFO: Application startup complete.
Nếu ta vào http://127.0.0.1:8000 thì sẽ như cách 1.
Thay vào đó ta vào http://127.0.0.1:8000/docs, thì khi này sẽ xuất hiện một GUI với cấu trúc như hình
Với từng request ta đã thiết kế, thì sẽ cho ra từng response tương ứng.
Ta có thể test từng request bằng cách ấn nút "Try it out", và ấn nút "Execute".
Với /generate request, thì ta phải thêm input trong phần "Edit value" sau khi đã ấn nút "Try it out", sau đó ấn nút "Execute".
Link Drive: https://drive.google.com/file/d/1uJ_vNEqMPwdsWDQAlHb6CiKxAEYRKr25/view?usp=sharing
12 commits
Python
100.0%
Dùng git bash, nhập lệnh:
$ git clone https://github.com/tvdeev206/FastAPIProject.git
$ cd FastAPIProject
Dùng python terminal, nhập lệnh:
$ python -m venv venv
$ venv\Scripts\activate
Dùng python terminal, nhập lệnh:
$ pip install -r requirements.txt
Dùng python terminal, nhập lệnh:
$ uvicorn main:app --reload
Khi này trên terminal sẽ thông báo:
INFO: Will watch for changes in these directories: ['C:\\Users\\Windows\\PycharmProjects\\FastAPIProject']
INFO: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
INFO: Started reloader process [28432] using WatchFiles
Tức là Server đã được khởi tạo và được host ở http://127.0.0.1:8000.
Khi này ta có thể copy URL và paste lên web hoặc ấn vào link URL.
Nhưng khi này ta chưa gửi request nên sẽ web sẽ không load được.
Mở thêm một terminal và nhập lệnh:
$ python test_get.py
hoặc
$ python test_gethealth.py
hoặc
$ python prompt.py
Với test_get.py file, thì ở trên web và terminal sẽ hiện một đoạn giới thiệu về mô hình, chức năng của mô hình và kiến trúc của hệ thống.
Với test_gethealth.py file, thì ở terminal sẽ hiện ra tình trạng của hệ thống ở dạng JSON
{'status': 'ok'}
Với prompt.py file, thì terminal sẽ cần cung cấp input đầu vào là "prompt" và "role", khi này ta cần nhập dữ liệu đầu vào, sau đó thì terminal sẽ hiện ra output là văn bản dựa trên input đầu vào, ví dụ:
Dữ liệu đầu vào:
$ Enter a prompt: Explain Machine learning
$ Enter a role: As an expert in Computer Science
Dữ liệu ra:
{'prompt': [{'role': 'As an expert in Computer Science', 'content': 'Explain Machine learning'}], 'generated_text': 'Machine learning is a subset of artificial intelligence that focuses on enabling computers to learn from data without being ex
plicitly programmed. Instead of following a strict set of rules, machine learning algorithms analyze patterns in large datasets to make predictions or decisions. \n\nThe process typically involves three stages: \n1. **Data Collection** – Gat
hering relevant information from sources like sensors, websites, or databases. \n2. **Feature Extraction** – Identifying the most important features or variables that contribute to the outcome. \n3. **Model Training** – Using the extracted f
eatures to train a statistical model, which learns from the data to improve its accuracy over time. \n\nMachine learning excels in scenarios where data is abundant and complex, such as image recognition, natural language processing, recommend
ation systems, and predictive analytics. It is widely applied in industries like healthcare, finance, marketing, and autonomous vehicles, where the ability to adapt and improve continuously is critical. \n\nWould you like me to also explain **how'}
Tại python terminal, nhập lệnh:
$ pip install "fastapi[standard]"
Sau đó, nhập lệnh:
$ fastapi dev
Khi này ở terminal sẽ xuất hiện
╭────────── FastAPI CLI - Development mode ───────────╮
│ │
│ Serving at: http://127.0.0.1:8000 │
│ │
│ API docs: http://127.0.0.1:8000/docs │
│ │
│ Running in development mode, for production use: │
│ │
│ fastapi run │
│ │
╰─────────────────────────────────────────────────────╯
INFO: Will watch for changes in these directories: ['/home/user/code/awesomeapp']
INFO: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
INFO: Started reloader process [2248755] using WatchFiles
INFO: Started server process [2248757]
INFO: Waiting for application startup.
INFO: Application startup complete.
Nếu ta vào http://127.0.0.1:8000 thì sẽ như cách 1.
Thay vào đó ta vào http://127.0.0.1:8000/docs, thì khi này sẽ xuất hiện một GUI với cấu trúc như hình
Với từng request ta đã thiết kế, thì sẽ cho ra từng response tương ứng.
Ta có thể test từng request bằng cách ấn nút "Try it out", và ấn nút "Execute".
Với /generate request, thì ta phải thêm input trong phần "Edit value" sau khi đã ấn nút "Try it out", sau đó ấn nút "Execute".
Link Drive: https://drive.google.com/file/d/1uJ_vNEqMPwdsWDQAlHb6CiKxAEYRKr25/view?usp=sharing
12 commits
Python
100.0%