deepak6593 commited on
Commit
3f63bad
·
1 Parent(s): 4ad233e

adding new files

Browse files
Files changed (2) hide show
  1. app.py +45 -28
  2. requirements.txt +2 -1
app.py CHANGED
@@ -1,30 +1,47 @@
1
  import gradio as gr
2
  import pandas as pd
3
- import seaborn as sns
4
- import matplotlib.pyplot as plt
5
-
6
-
7
- def plot_pens(category1, value1, category2, value2, category3, value3, category4, value4, category5, value5):
8
- df_pens = pd.DataFrame(
9
- {
10
- "category": [category1, category2, category3, category4, category5],
11
- "inventory": [value1, value2, value3, value4, value5],
12
- }
13
- )
14
- fig, ax = plt.subplots()
15
- ax.plot(df_pens['category'], df_pens['inventory'], marker='o', linestyle='-', color='b')
16
- ax.set_xlabel('Category')
17
- ax.set_ylabel('Inventory')
18
- ax.set_title('Line Chart of Pens Inventory')
19
- return fig
20
-
21
-
22
- iface = gr.Interface(
23
- fn=plot_pens,
24
- inputs=['textbox', 'number', 'textbox', 'number', 'textbox', 'number', 'textbox', 'number', 'textbox', 'number'],
25
- outputs=['plot'],
26
- title="Line Chart of Pens Inventory",
27
- description="Visualize the inventory of pens with a line chart.",
28
- article="Talk more about the pens here, shall we?",
29
- theme='peach'
30
- ).launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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