Spaces:
Sleeping
Sleeping
Commit
·
2cfbf68
1
Parent(s):
77770c5
adding files
Browse files- Dockerfile +1 -13
- __pycache__/main.cpython-311.pyc +0 -0
- gradio_app.py +0 -21
- main.py +67 -25
- ow-stu-us-ce1-dev.json +13 -0
- requirements.txt +2 -1
- test.db +0 -0
Dockerfile
CHANGED
|
@@ -1,15 +1,3 @@
|
|
| 1 |
-
# FROM python:3.9
|
| 2 |
-
|
| 3 |
-
# WORKDIR /code
|
| 4 |
-
|
| 5 |
-
# COPY ./requirements.txt /code/requirements.txt
|
| 6 |
-
|
| 7 |
-
# RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
|
| 8 |
-
|
| 9 |
-
# COPY . .
|
| 10 |
-
|
| 11 |
-
# CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]
|
| 12 |
-
|
| 13 |
# Use the official Python image
|
| 14 |
FROM python:3.9
|
| 15 |
|
|
@@ -29,4 +17,4 @@ RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
|
|
| 29 |
COPY . /code/
|
| 30 |
|
| 31 |
# Command to run on container start
|
| 32 |
-
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
# Use the official Python image
|
| 2 |
FROM python:3.9
|
| 3 |
|
|
|
|
| 17 |
COPY . /code/
|
| 18 |
|
| 19 |
# Command to run on container start
|
| 20 |
+
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8123"]
|
__pycache__/main.cpython-311.pyc
CHANGED
|
Binary files a/__pycache__/main.cpython-311.pyc and b/__pycache__/main.cpython-311.pyc differ
|
|
|
gradio_app.py
DELETED
|
@@ -1,21 +0,0 @@
|
|
| 1 |
-
import gradio as gr
|
| 2 |
-
import pandas as pd
|
| 3 |
-
|
| 4 |
-
simple = pd.DataFrame(
|
| 5 |
-
{
|
| 6 |
-
"item": ["A", "B", "C", "D", "E", "F", "G", "H", "I"],
|
| 7 |
-
"inventory": [28, 55, 43, 91, 81, 53, 19, 87, 52],
|
| 8 |
-
}
|
| 9 |
-
)
|
| 10 |
-
|
| 11 |
-
with gr.Blocks() as demo:
|
| 12 |
-
gr.BarPlot(
|
| 13 |
-
value=simple,
|
| 14 |
-
x="item",
|
| 15 |
-
y="inventory",
|
| 16 |
-
title="Simple Bar Plot",
|
| 17 |
-
container=False,
|
| 18 |
-
)
|
| 19 |
-
|
| 20 |
-
if __name__ == "__main__":
|
| 21 |
-
demo.launch(share=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
main.py
CHANGED
|
@@ -1,28 +1,70 @@
|
|
| 1 |
-
from fastapi import FastAPI,
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
import
|
| 6 |
-
from gradio_client import Client
|
| 7 |
|
| 8 |
app = FastAPI()
|
| 9 |
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
#
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import FastAPI, File, UploadFile, Form
|
| 2 |
+
import pandas as pd
|
| 3 |
+
from google.cloud import storage
|
| 4 |
+
import io
|
| 5 |
+
import os
|
|
|
|
| 6 |
|
| 7 |
app = FastAPI()
|
| 8 |
|
| 9 |
+
# GCS credentials
|
| 10 |
+
gcs_credentials_file = "ow-stu-us-ce1-dev.json"
|
| 11 |
+
gcs_bucket_name = "ow-stu-us-ce1-ai-platform"
|
| 12 |
+
|
| 13 |
+
# Ensure the GCS bucket exists
|
| 14 |
+
gcs_client = storage.Client.from_service_account_json(gcs_credentials_file)
|
| 15 |
+
gcs_bucket = gcs_client.bucket(gcs_bucket_name)
|
| 16 |
+
|
| 17 |
+
# File path in GCS bucket
|
| 18 |
+
gcs_file_path = "deepak_6593/db.csv"
|
| 19 |
+
|
| 20 |
+
def append_to_gcs_csv(new_data, gcs_file_path):
|
| 21 |
+
# Standardize column names for new data
|
| 22 |
+
new_data.columns = ['category', 'score']
|
| 23 |
+
|
| 24 |
+
# Check if the file exists in GCS bucket
|
| 25 |
+
blob = gcs_bucket.blob(gcs_file_path)
|
| 26 |
+
exists = blob.exists()
|
| 27 |
+
|
| 28 |
+
# If file exists, read it into a DataFrame
|
| 29 |
+
if exists:
|
| 30 |
+
existing_data = pd.read_csv(io.BytesIO(blob.download_as_bytes()))
|
| 31 |
+
# Ensure existing data has the right columns
|
| 32 |
+
existing_data = existing_data[['category', 'score']]
|
| 33 |
+
# Append new data to existing data
|
| 34 |
+
combined_data = pd.concat([existing_data, new_data], ignore_index=True)
|
| 35 |
+
else:
|
| 36 |
+
combined_data = new_data
|
| 37 |
+
|
| 38 |
+
# Convert combined DataFrame to CSV and upload it
|
| 39 |
+
csv_data = combined_data.to_csv(index=False).encode('utf-8')
|
| 40 |
+
blob.upload_from_string(csv_data, content_type='text/csv')
|
| 41 |
+
|
| 42 |
+
def read_from_gcs_csv(gcs_file_path):
|
| 43 |
+
blob = gcs_bucket.blob(gcs_file_path)
|
| 44 |
+
return pd.read_csv(io.BytesIO(blob.download_as_text()))
|
| 45 |
+
|
| 46 |
+
@app.post("/upload-file/")
|
| 47 |
+
async def upload_file(file: UploadFile = File(...)):
|
| 48 |
+
df = pd.read_csv(io.StringIO((await file.read()).decode('utf-8')))
|
| 49 |
+
append_to_gcs_csv(df, gcs_file_path)
|
| 50 |
+
return {"message": "File uploaded successfully"}
|
| 51 |
+
|
| 52 |
+
@app.post("/upload-data/")
|
| 53 |
+
async def upload_data(category: str = Form(...), score: float = Form(...)):
|
| 54 |
+
df = pd.DataFrame([[category, score]], columns=['category', 'score'])
|
| 55 |
+
append_to_gcs_csv(df, gcs_file_path)
|
| 56 |
+
return {"message": "Data uploaded successfully"}
|
| 57 |
+
|
| 58 |
+
@app.post("/clear-data/")
|
| 59 |
+
async def clear_data():
|
| 60 |
+
# Create an empty DataFrame with the same columns
|
| 61 |
+
empty_df = pd.DataFrame(columns=['category', 'score'])
|
| 62 |
+
# Convert the empty DataFrame to CSV
|
| 63 |
+
csv_data = empty_df.to_csv(index=False).encode('utf-8')
|
| 64 |
+
# Overwrite the existing file in GCS with the empty CSV data
|
| 65 |
+
gcs_bucket.blob(gcs_file_path).upload_from_string(csv_data, content_type='text/csv')
|
| 66 |
+
return {"message": "Data cleared successfully"}
|
| 67 |
+
|
| 68 |
+
if __name__ == "__main__":
|
| 69 |
+
import uvicorn
|
| 70 |
+
uvicorn.run(app, host="0.0.0.0", port=8123)
|
ow-stu-us-ce1-dev.json
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"type": "service_account",
|
| 3 |
+
"project_id": "ow-stu-us-ce1-dev",
|
| 4 |
+
"private_key_id": "1a9e8df697e5d4fbc088971f6eff64818b4b3361",
|
| 5 |
+
"private_key": "-----BE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Pt8tRVDdMrPmw6IFPB2OWQPwnKnf1GYE9ChuG6y00iKZVVFB\ndmWHvPaTrwKBgCWGXulrVDovtw6jeSELfrivQ0CmNKwv/fibmdrAmg4ttlJc6rer\nL2i9NegbN9IU5x0vLzibAmZ+VV32KA/HWMNSVpr/bOTaHpyYUQdKyHWs3DoMQvKl\ntg9/tUxHEaDJL9bhRJ3/sv8Ks+z656qn+bzLlgrkU6vHG7b7DosZavM7AoGARI6C\n1qvhSp+TmN1UROWusAFaQngR696UNtDkoRlfn+8c7t73RZoohxR6WbbKT8PF4ccs\n63ugJzGDuJKLgEkEv4A/SJjvX3ApBRXdyz17w3C2d+hVCbcDD+mN3RZe/jkaXloY\nziLYBtUSZT1xAeBe78PfKVoIyCuDoN7OrWAGeeUCgYEAh1kbA0y7v/l5fm4grdFr\nfD7hs/uIf4ShI6QyIeghhRUS63Bprvgfc01Ex3wuKzBC/KCSTbBZeBbY1Z5+yDGB\noeobCicOcOBkKFSdtE21alBr8VSnbxHrKJLePQ/XSJW6FakbGF9dMd13kW3tKrp3\nwpumRo/yxJKI/bTC/83mmFA=\n-----END PRIVATE KEY-----\n",
|
| 6 |
+
"client_email": "gbucket@ow-stu-us-ce1-dev.iam.gserviceaccount.com",
|
| 7 |
+
"client_id": "109031272746562148979",
|
| 8 |
+
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
|
| 9 |
+
"token_uri": "https://oauth2.googleapis.com/token",
|
| 10 |
+
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
|
| 11 |
+
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/gbucket%40ow-stu-us-ce1-dev.iam.gserviceaccount.com",
|
| 12 |
+
"universe_domain": "googleapis.com"
|
| 13 |
+
}
|
requirements.txt
CHANGED
|
@@ -2,4 +2,5 @@ fastapi
|
|
| 2 |
uvicorn
|
| 3 |
pandas
|
| 4 |
gradio
|
| 5 |
-
sqlalchemy
|
|
|
|
|
|
| 2 |
uvicorn
|
| 3 |
pandas
|
| 4 |
gradio
|
| 5 |
+
sqlalchemy
|
| 6 |
+
google-cloud-storage
|
test.db
DELETED
|
File without changes
|