Update app.py
Browse files
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 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
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 |
+
|