rahulcg commited on
Commit
4409742
1 Parent(s): 2eb3dcb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +74 -72
app.py CHANGED
@@ -1,72 +1,74 @@
1
- import streamlit as st
2
- from lida import Manager, TextGenerationConfig , llm
3
- from dotenv import load_dotenv
4
- import os
5
- import openai
6
- from PIL import Image
7
- from io import BytesIO
8
- import base64
9
-
10
- load_dotenv()
11
- openai.api_key = os.getenv('OPENAI_API_KEY')
12
-
13
- def base64_to_image(base64_string):
14
- # Decode the base64 string
15
- byte_data = base64.b64decode(base64_string)
16
-
17
- # Use BytesIO to convert the byte data to image
18
- return Image.open(BytesIO(byte_data))
19
-
20
-
21
- lida = Manager(text_gen = llm(provider="hf", model="uukuguy/speechless-llama2-hermes-orca-platypus-13b", device_map="auto"))
22
- textgen_config = TextGenerationConfig(n=1, temperature=0.5, use_cache=True)
23
-
24
- menu = st.sidebar.selectbox("Choose an Option", ["Summarize", "Question based Graph"])
25
-
26
- if menu == "Summarize":
27
- st.subheader("Summarization of your Data")
28
- file_uploader = st.file_uploader("Upload your CSV", type="csv")
29
- if file_uploader is not None:
30
- path_to_save = "filename.csv"
31
- with open(path_to_save, "wb") as f:
32
- f.write(file_uploader.getvalue())
33
- summary = lida.summarize("filename.csv", summary_method="default", textgen_config=textgen_config)
34
- st.write(summary)
35
- goals = lida.goals(summary, n=2, textgen_config=textgen_config)
36
- for goal in goals:
37
- st.write(goal)
38
- i = 0
39
- library = "seaborn"
40
- textgen_config = TextGenerationConfig(n=1, temperature=0.2, use_cache=True)
41
- charts = lida.visualize(summary=summary, goal=goals[i], textgen_config=textgen_config, library=library)
42
- img_base64_string = charts[0].raster
43
- img = base64_to_image(img_base64_string)
44
- st.image(img)
45
-
46
-
47
-
48
-
49
- elif menu == "Question based Graph":
50
- st.subheader("Query your Data to Generate Graph")
51
- file_uploader = st.file_uploader("Upload your CSV", type="csv")
52
- if file_uploader is not None:
53
- path_to_save = "filename1.csv"
54
- with open(path_to_save, "wb") as f:
55
- f.write(file_uploader.getvalue())
56
- text_area = st.text_area("Query your Data to Generate Graph", height=200)
57
- if st.button("Generate Graph"):
58
- if len(text_area) > 0:
59
- st.info("Your Query: " + text_area)
60
- lida = Manager(text_gen = llm("openai"))
61
- textgen_config = TextGenerationConfig(n=1, temperature=0.2, use_cache=True)
62
- summary = lida.summarize("filename1.csv", summary_method="default", textgen_config=textgen_config)
63
- user_query = text_area
64
- charts = lida.visualize(summary=summary, goal=user_query, textgen_config=textgen_config)
65
- charts[0]
66
- image_base64 = charts[0].raster
67
- img = base64_to_image(image_base64)
68
- st.image(img)
69
-
70
-
71
-
72
-
 
 
 
1
+ import streamlit as st
2
+ from lida import Manager, TextGenerationConfig , llm
3
+ from dotenv import load_dotenv
4
+ import os
5
+ import openai
6
+ from PIL import Image
7
+ from io import BytesIO
8
+ import base64
9
+ from accelerate import disk_offload
10
+
11
+ load_dotenv()
12
+ openai.api_key = os.getenv('OPENAI_API_KEY')
13
+
14
+ def base64_to_image(base64_string):
15
+ # Decode the base64 string
16
+ byte_data = base64.b64decode(base64_string)
17
+
18
+ # Use BytesIO to convert the byte data to image
19
+ return Image.open(BytesIO(byte_data))
20
+
21
+
22
+ lida = Manager(text_gen = llm(provider="hf", model="uukuguy/speechless-llama2-hermes-orca-platypus-13b", device_map="auto"))
23
+ disk_offload(model=lida, offload_dir="offload")
24
+ textgen_config = TextGenerationConfig(n=1, temperature=0.5, use_cache=True)
25
+
26
+ menu = st.sidebar.selectbox("Choose an Option", ["Summarize", "Question based Graph"])
27
+
28
+ if menu == "Summarize":
29
+ st.subheader("Summarization of your Data")
30
+ file_uploader = st.file_uploader("Upload your CSV", type="csv")
31
+ if file_uploader is not None:
32
+ path_to_save = "filename.csv"
33
+ with open(path_to_save, "wb") as f:
34
+ f.write(file_uploader.getvalue())
35
+ summary = lida.summarize("filename.csv", summary_method="default", textgen_config=textgen_config)
36
+ st.write(summary)
37
+ goals = lida.goals(summary, n=2, textgen_config=textgen_config)
38
+ for goal in goals:
39
+ st.write(goal)
40
+ i = 0
41
+ library = "seaborn"
42
+ textgen_config = TextGenerationConfig(n=1, temperature=0.2, use_cache=True)
43
+ charts = lida.visualize(summary=summary, goal=goals[i], textgen_config=textgen_config, library=library)
44
+ img_base64_string = charts[0].raster
45
+ img = base64_to_image(img_base64_string)
46
+ st.image(img)
47
+
48
+
49
+
50
+
51
+ elif menu == "Question based Graph":
52
+ st.subheader("Query your Data to Generate Graph")
53
+ file_uploader = st.file_uploader("Upload your CSV", type="csv")
54
+ if file_uploader is not None:
55
+ path_to_save = "filename1.csv"
56
+ with open(path_to_save, "wb") as f:
57
+ f.write(file_uploader.getvalue())
58
+ text_area = st.text_area("Query your Data to Generate Graph", height=200)
59
+ if st.button("Generate Graph"):
60
+ if len(text_area) > 0:
61
+ st.info("Your Query: " + text_area)
62
+ lida = Manager(text_gen = llm("openai"))
63
+ textgen_config = TextGenerationConfig(n=1, temperature=0.2, use_cache=True)
64
+ summary = lida.summarize("filename1.csv", summary_method="default", textgen_config=textgen_config)
65
+ user_query = text_area
66
+ charts = lida.visualize(summary=summary, goal=user_query, textgen_config=textgen_config)
67
+ charts[0]
68
+ image_base64 = charts[0].raster
69
+ img = base64_to_image(image_base64)
70
+ st.image(img)
71
+
72
+
73
+
74
+