Spaces:
Runtime error
Runtime error
Commit
·
3f63bad
1
Parent(s):
4ad233e
adding new files
Browse files- app.py +45 -28
- requirements.txt +2 -1
app.py
CHANGED
|
@@ -1,30 +1,47 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import pandas as pd
|
| 3 |
-
|
| 4 |
-
import
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import pandas as pd
|
| 3 |
+
from google.cloud import storage
|
| 4 |
+
import io
|
| 5 |
+
import os
|
| 6 |
+
import json
|
| 7 |
+
import tempfile
|
| 8 |
+
|
| 9 |
+
gcs_bucket_name = "ow-stu-us-ce1-ai-platform"
|
| 10 |
+
|
| 11 |
+
# File path in GCS bucket
|
| 12 |
+
gcs_file_path = "deepak_6593/db.csv"
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
# process of getting credentials
|
| 16 |
+
def get_credentials():
|
| 17 |
+
creds_json_str = os.getenv("BOB") # get json credentials stored as a string
|
| 18 |
+
if creds_json_str is None:
|
| 19 |
+
raise ValueError("GOOGLE_APPLICATION_CREDENTIALS_JSON not found in environment")
|
| 20 |
+
|
| 21 |
+
# create a temporary file
|
| 22 |
+
with tempfile.NamedTemporaryFile(mode="w+", delete=False, suffix=".json") as temp:
|
| 23 |
+
temp.write(creds_json_str) # write in json format
|
| 24 |
+
temp_filename = temp.name
|
| 25 |
+
|
| 26 |
+
return temp_filename
|
| 27 |
+
|
| 28 |
+
# pass
|
| 29 |
+
os.environ["GOOGLE_APPLICATION_CREDENTIALS"]= get_credentials()
|
| 30 |
+
|
| 31 |
+
# Ensure the GCS bucket exists
|
| 32 |
+
gcs_client = storage.Client()
|
| 33 |
+
gcs_bucket = gcs_client.bucket(gcs_bucket_name)
|
| 34 |
+
|
| 35 |
+
def get_data():
|
| 36 |
+
blob = gcs_bucket.blob(gcs_file_path)
|
| 37 |
+
return pd.read_csv(io.BytesIO(blob.download_as_bytes()))
|
| 38 |
+
|
| 39 |
+
with gr.Blocks() as demo:
|
| 40 |
+
gr.Markdown("# 📈 Real-Time Line Plot")
|
| 41 |
+
with gr.Row():
|
| 42 |
+
with gr.Column():
|
| 43 |
+
gr.DataFrame(get_data, every=1)
|
| 44 |
+
with gr.Column():
|
| 45 |
+
gr.LinePlot(get_data, every=1, x="category", y="score", y_title="score(marks)", overlay_point=True, width=500, height=500)
|
| 46 |
+
|
| 47 |
+
demo.queue().launch()
|
requirements.txt
CHANGED
|
@@ -1,4 +1,5 @@
|
|
| 1 |
gradio
|
| 2 |
pandas
|
| 3 |
seaborn
|
| 4 |
-
matplotlib
|
|
|
|
|
|
| 1 |
gradio
|
| 2 |
pandas
|
| 3 |
seaborn
|
| 4 |
+
matplotlib
|
| 5 |
+
google-cloud-storage
|