Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified .DS_Store
Binary file not shown.
33 changes: 33 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"name": "Python 3",
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
"image": "mcr.microsoft.com/devcontainers/python:1-3.11-bullseye",
"customizations": {
"codespaces": {
"openFiles": [
"README.md",
"BaseCamp3/Day_2/calculator.py"
]
},
"vscode": {
"settings": {},
"extensions": [
"ms-python.python",
"ms-python.vscode-pylance"
]
}
},
"updateContentCommand": "[ -f packages.txt ] && sudo apt update && sudo apt upgrade -y && sudo xargs apt install -y <packages.txt; [ -f requirements.txt ] && pip3 install --user -r requirements.txt; pip3 install --user streamlit; echo '✅ Packages installed and Requirements met'",
"postAttachCommand": {
"server": "streamlit run BaseCamp3/Day_2/calculator.py --server.enableCORS false --server.enableXsrfProtection false"
},
"portsAttributes": {
"8501": {
"label": "Application",
"onAutoForward": "openPreview"
}
},
"forwardPorts": [
8501
]
}
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
**/.ipynb_checkpoints
*.py[cod]
*$py.class

**/csv_files
**/*.pkl
**/*_solution
**/github_pat.txt
# C extensions
*.so

Expand Down
10 changes: 5 additions & 5 deletions BaseCamp3/Day_1/2a_calculator.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@
@app.get("/add")
def add(a, b):
"""Add two numbers and return the result."""
# result = float(a) + float(b)
result = a+b
result = float(a) + float(b)
# result = a+b
return {"operation": "add", "a": a, "b": b, "result": result}

@app.get("/subtract")
def subtract(a, b):
"""Subtract b from a and return the result."""
# result = float(a) - float(b)
result = a-b
result = float(a) - float(b)
# result = a-b
return {"operation": "subtract", "a": a, "b": b, "result": result}

@app.get("/")
Expand All @@ -32,6 +32,6 @@ def read_root():

'''
import requests
response = requests.get("http://0.0.0.0:9321/add", params={"a": 5, "b": 3})
response = requests.get("http://localhost:9321/add", params={"a": 5, "b": 3})
print(response.json())
'''
8 changes: 4 additions & 4 deletions BaseCamp3/Day_1/2b_calculator.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@
@app.get("/add")
def add(a, b):
"""Add two numbers and return the result."""
# result = float(a) + float(b)
result = a+b
result = float(a) + float(b)
# result = a+b
return {"operation": "add", "a": a, "b": b, "result": result}

@app.get("/subtract")
def subtract(a, b):
"""Subtract b from a and return the result."""
# result = float(a) - float(b)
result = a-b
result = float(a) - float(b)
# result = a-b
return {"operation": "subtract", "a": a, "b": b, "result": result}

@app.get("/")
Expand Down
11 changes: 8 additions & 3 deletions BaseCamp3/Day_2/calculator.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@
st.write("This app connects to a FastAPI calculator service.")

# Define the API base URL
api_url = "http://0.0.0.0:9321"
<<<<<<< HEAD
=======
# api_url = "http://0.0.0.0:9321"
>>>>>>> efc449e (added week3 content)
api_url = "https://genaiengineering-cohort2-uzeu.onrender.com"

# Initialize session state to store the calculator display and current operation
if 'display' not in st.session_state:
Expand Down Expand Up @@ -63,7 +67,8 @@ def calculate_result():
endpoint = f"{api_url}/{st.session_state.operation}"

# Make the API call
response = requests.get(endpoint, params={"a": first_num, "b": second_num})
# response = requests.get(endpoint, params={"a": first_num, "b": second_num})
response = requests.post(endpoint, json={"a": first_num, "b": second_num})

# Check if the request was successful
if response.status_code == 200:
Expand Down Expand Up @@ -138,4 +143,4 @@ def calculate_result():
4. Click "C" to clear the calculator
""")

# Run with: streamlit run streamlit_calculator.py
# Run with: streamlit run streamlit_calculator.py
Loading