Spaces:
Runtime error
Runtime error
Commit
•
4b30b1b
1
Parent(s):
66778f1
Upload 2 files
Browse files- app.py +79 -0
- requirements.txt +4 -0
app.py
ADDED
@@ -0,0 +1,79 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from lida import Manager, TextGenerationConfig, llm
|
3 |
+
from dotenv import load_dotenv
|
4 |
+
import os
|
5 |
+
import io
|
6 |
+
from PIL import Image
|
7 |
+
from io import BytesIO
|
8 |
+
import base64
|
9 |
+
|
10 |
+
HUGGINGFACE_API_TOKEN = os.environ.get('HF_TOKEN')
|
11 |
+
|
12 |
+
def base64_to_image(base64_string):
|
13 |
+
|
14 |
+
byte_data = base64.b64decode(base64_string)
|
15 |
+
|
16 |
+
return Image.open(BytesIO(byte_data))
|
17 |
+
|
18 |
+
|
19 |
+
|
20 |
+
#from LIDA github
|
21 |
+
text_gen = llm(model="uukuguy/speechless-llama2-hermes-orca-platypus-13b", device_map="auto")
|
22 |
+
|
23 |
+
lida = Manager(text_gen=text_gen)
|
24 |
+
|
25 |
+
|
26 |
+
|
27 |
+
|
28 |
+
textgen_config = TextGenerationConfig(n=1, temperature=0.1, max_tokens=512)
|
29 |
+
|
30 |
+
|
31 |
+
menu = st.sidebar.selectbox("Summary or Query", ["Summary", "Query"])
|
32 |
+
|
33 |
+
if menu == "Summary":
|
34 |
+
st.subheader("Summarization of the Data")
|
35 |
+
file_uploader = st.file_uploader("Upload your file", type="csv")
|
36 |
+
if file_uploader is not None:
|
37 |
+
path_to_save = "filename.csv"
|
38 |
+
with open(path_to_save, "wb") as f:
|
39 |
+
f.write(file_uploader.getvalue())
|
40 |
+
summary = lida.summarize("filename.csv", summary_method="default")
|
41 |
+
st.write(summary)
|
42 |
+
goals = lida.goals(summary, n=2, textgen_config=textgen_config)
|
43 |
+
for goal in goals:
|
44 |
+
st.write(goal)
|
45 |
+
i = 0
|
46 |
+
library = "seaborn"
|
47 |
+
text_gen_config = TextGenerationConfig(n=1, temperature=0.1, use_cache=True)
|
48 |
+
charts = lida.visualize(summary=summary, goal=goals[i], textgen_config=textgen_config, library=library)
|
49 |
+
img_base64_string = charts[0].raster
|
50 |
+
img = base64_to_image(img_base64_string)
|
51 |
+
st.image(img)
|
52 |
+
|
53 |
+
elif menu == "Query":
|
54 |
+
st.subheader("Questioning of the Data")
|
55 |
+
file_uploader = st.file_uploader("Upload your file", type="csv")
|
56 |
+
if file_uploader is not None:
|
57 |
+
path_to_save = "filename1.csv"
|
58 |
+
with open(path_to_save, "wb") as f:
|
59 |
+
f.write(file_uploader.getvalue())
|
60 |
+
|
61 |
+
text_area = st.text_area("Query your data to generate visualization", height=200)
|
62 |
+
if st.button("Generate Graph"):
|
63 |
+
if len(text_area) > 0:
|
64 |
+
# st.info("Your query " + text_area)
|
65 |
+
# lida = Manager(text_gen=text_gen)
|
66 |
+
# text_gen_config = TextGenerationConfig(n=1, temperature=0.1, use_cache=True)
|
67 |
+
summary = lida.summarize("filename1.csv", summary_method="default", textgen_config=textgen_config)
|
68 |
+
user_query = text_area
|
69 |
+
charts = lida.visualize(summary=summary, goal=user_query, textgen_config=textgen_config)
|
70 |
+
img_base64_string = charts[0].raster
|
71 |
+
img = base64_to_image(img_base64_string)
|
72 |
+
st.image(img)
|
73 |
+
charts[0]
|
74 |
+
|
75 |
+
|
76 |
+
|
77 |
+
|
78 |
+
|
79 |
+
|
requirements.txt
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
lida
|
2 |
+
lida[transformers]
|
3 |
+
torch
|
4 |
+
streamlit
|