gradio_app / app.py
deepak6593's picture
adding new files
ef10df5
import gradio as gr
import pandas as pd
from google.cloud import storage
import io
import os
import tempfile
gcs_bucket_name = "ow-stu-us-ce1-ai-platform"
# File path in GCS bucket
gcs_file_path = "deepak_6593/db.csv"
# process of getting credentials
def get_credentials():
creds_json_str = os.getenv("BOB") # get json credentials stored as a string
if creds_json_str is None:
raise ValueError("GOOGLE_APPLICATION_CREDENTIALS_JSON not found in environment")
# create a temporary file
with tempfile.NamedTemporaryFile(mode="w+", delete=False, suffix=".json") as temp:
temp.write(creds_json_str) # write in json format
temp_filename = temp.name
return temp_filename
# pass
os.environ["GOOGLE_APPLICATION_CREDENTIALS"]= get_credentials()
# Ensure the GCS bucket exists
gcs_client = storage.Client()
gcs_bucket = gcs_client.bucket(gcs_bucket_name)
def get_data():
blob = gcs_bucket.blob(gcs_file_path)
return pd.read_csv(io.BytesIO(blob.download_as_bytes()))
with gr.Blocks() as demo:
gr.Markdown("# 📈 Real-Time Line Plot")
with gr.Row():
with gr.Column():
gr.DataFrame(get_data, every=1)
with gr.Column():
gr.LinePlot(get_data, every=1, x="category", y="score", y_title="score(marks)", overlay_point=True, width=500, height=500)
demo.queue().launch()