Spaces:
Sleeping
Sleeping
Atharva Thakur
commited on
Commit
•
b12237c
1
Parent(s):
3a7810d
report generator added
Browse files- Modules/data_QA.py +21 -1
- Modules/llm_summary.py +1 -1
- Modules/output_interpreter.py +75 -1
- app.py +1 -1
- requirements.txt +3 -1
Modules/data_QA.py
CHANGED
@@ -6,7 +6,7 @@ from dotenv import load_dotenv
|
|
6 |
import os
|
7 |
from Modules.code_runner import run_script
|
8 |
from Modules.code_debugger import code_debugger
|
9 |
-
from Modules.output_interpreter import output_interpreter
|
10 |
from Modules.data_code_gen import DataCodeGen
|
11 |
from Modules.python_interpreter import PythonInterpreter, run_interpreter
|
12 |
import subprocess
|
@@ -91,7 +91,27 @@ class DataQA:
|
|
91 |
# Process final output
|
92 |
answer = output_interpreter(query)
|
93 |
st.write(answer)
|
|
|
|
|
|
|
|
|
|
|
|
|
94 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
95 |
# Clean up by removing the code file
|
96 |
os.remove("code.py")
|
97 |
|
|
|
6 |
import os
|
7 |
from Modules.code_runner import run_script
|
8 |
from Modules.code_debugger import code_debugger
|
9 |
+
from Modules.output_interpreter import output_interpreter,display_pdf,create_combined_pdf
|
10 |
from Modules.data_code_gen import DataCodeGen
|
11 |
from Modules.python_interpreter import PythonInterpreter, run_interpreter
|
12 |
import subprocess
|
|
|
91 |
# Process final output
|
92 |
answer = output_interpreter(query)
|
93 |
st.write(answer)
|
94 |
+
display_pdf("file.pdf")
|
95 |
+
# Specify the file paths
|
96 |
+
text_file = "data.txt"
|
97 |
+
code_file = "code.py"
|
98 |
+
figure_file = "file.pdf"
|
99 |
+
output_file = "report.pdf"
|
100 |
|
101 |
+
# Create the combined PDF
|
102 |
+
create_combined_pdf(text_file, code_file, figure_file, output_file)
|
103 |
+
|
104 |
+
pdf_file_path = "report.pdf"
|
105 |
+
|
106 |
+
# Read the PDF file content
|
107 |
+
with open(pdf_file_path, "rb") as pdf_file:
|
108 |
+
pdf_content = pdf_file.read()
|
109 |
+
st.download_button(
|
110 |
+
label="Download Report PDF",
|
111 |
+
data=pdf_content,
|
112 |
+
file_name="report.pdf",
|
113 |
+
mime="application/pdf"
|
114 |
+
)
|
115 |
# Clean up by removing the code file
|
116 |
os.remove("code.py")
|
117 |
|
Modules/llm_summary.py
CHANGED
@@ -8,7 +8,7 @@ load_dotenv() # take environment variables from .env.
|
|
8 |
os.environ['GEMINI_API_KEY'] = os.getenv("GOOGLE_API_KEY")
|
9 |
|
10 |
@st.cache_data(experimental_allow_widgets=True)
|
11 |
-
def LLM_summary():
|
12 |
file_path = './data.csv'
|
13 |
df = pd.read_csv(file_path)
|
14 |
|
|
|
8 |
os.environ['GEMINI_API_KEY'] = os.getenv("GOOGLE_API_KEY")
|
9 |
|
10 |
@st.cache_data(experimental_allow_widgets=True)
|
11 |
+
def LLM_summary(data):
|
12 |
file_path = './data.csv'
|
13 |
df = pd.read_csv(file_path)
|
14 |
|
Modules/output_interpreter.py
CHANGED
@@ -1,6 +1,14 @@
|
|
1 |
from litellm import completion
|
2 |
from dotenv import load_dotenv
|
3 |
import os
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
|
5 |
load_dotenv() # take environment variables from .env.
|
6 |
|
@@ -24,4 +32,70 @@ def output_interpreter(query):
|
|
24 |
)
|
25 |
|
26 |
response = output.choices[0].message.content
|
27 |
-
return response
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
from litellm import completion
|
2 |
from dotenv import load_dotenv
|
3 |
import os
|
4 |
+
import streamlit as st
|
5 |
+
import base64
|
6 |
+
|
7 |
+
from reportlab.lib.pagesizes import letter
|
8 |
+
from reportlab.pdfgen import canvas
|
9 |
+
from reportlab.lib.utils import ImageReader
|
10 |
+
import PyPDF2
|
11 |
+
import io
|
12 |
|
13 |
load_dotenv() # take environment variables from .env.
|
14 |
|
|
|
32 |
)
|
33 |
|
34 |
response = output.choices[0].message.content
|
35 |
+
return response
|
36 |
+
|
37 |
+
def display_pdf(file_path):
|
38 |
+
with open(file_path, "rb") as f:
|
39 |
+
base64_pdf = base64.b64encode(f.read()).decode('utf-8')
|
40 |
+
pdf_display = f'<iframe src="data:application/pdf;base64,{base64_pdf}" width="700" height="1000" type="application/pdf"></iframe>'
|
41 |
+
st.markdown(pdf_display, unsafe_allow_html=True)
|
42 |
+
|
43 |
+
|
44 |
+
|
45 |
+
|
46 |
+
def create_combined_pdf(text_file, code_file, figure_file, output_file):
|
47 |
+
# Create a canvas object
|
48 |
+
packet = io.BytesIO()
|
49 |
+
can = canvas.Canvas(packet, pagesize=letter)
|
50 |
+
|
51 |
+
# Add text content from data.txt
|
52 |
+
with open(text_file, 'r') as file:
|
53 |
+
text = file.read()
|
54 |
+
can.drawString(72, 750, "Text Content from data.txt:")
|
55 |
+
text_lines = text.split('\n')
|
56 |
+
y = 730
|
57 |
+
for line in text_lines:
|
58 |
+
can.drawString(72, y, line)
|
59 |
+
y -= 15
|
60 |
+
|
61 |
+
# Add some space between sections
|
62 |
+
y -= 30
|
63 |
+
|
64 |
+
# Add code content from code.py
|
65 |
+
with open(code_file, 'r') as file:
|
66 |
+
code = file.read()
|
67 |
+
can.drawString(72, y, "Code Content from code.py:")
|
68 |
+
y -= 20
|
69 |
+
code_lines = code.split('\n')
|
70 |
+
for line in code_lines:
|
71 |
+
if y < 50: # Prevent printing beyond the page
|
72 |
+
can.showPage()
|
73 |
+
y = 750
|
74 |
+
can.drawString(72, y, line)
|
75 |
+
y -= 15
|
76 |
+
|
77 |
+
# Save the canvas content to the packet
|
78 |
+
can.save()
|
79 |
+
|
80 |
+
# Move to the beginning of the StringIO buffer
|
81 |
+
packet.seek(0)
|
82 |
+
new_pdf = PyPDF2.PdfReader(packet)
|
83 |
+
|
84 |
+
# Read the existing PDF (figure)
|
85 |
+
existing_pdf = PyPDF2.PdfReader(open(figure_file, "rb"))
|
86 |
+
|
87 |
+
# Create a PdfFileWriter object to combine the PDFs
|
88 |
+
output = PyPDF2.PdfWriter()
|
89 |
+
|
90 |
+
# Add the new PDF (text and code)
|
91 |
+
output.add_page(new_pdf.pages[0])
|
92 |
+
|
93 |
+
# Add the existing PDF (figure)
|
94 |
+
for page_num in range(len(existing_pdf.pages)):
|
95 |
+
output.add_page(existing_pdf.pages[page_num])
|
96 |
+
|
97 |
+
# Write the combined PDF to a file
|
98 |
+
with open(output_file, "wb") as outputStream:
|
99 |
+
output.write(outputStream)
|
100 |
+
|
101 |
+
|
app.py
CHANGED
@@ -46,7 +46,7 @@ def main():
|
|
46 |
data = pd.read_csv("data.csv")
|
47 |
data_analyzer = DataAnalyzer(data)
|
48 |
data_analyzer.show_eda()
|
49 |
-
LLM_summary()
|
50 |
|
51 |
data_analyzer.show_count_plots()
|
52 |
|
|
|
46 |
data = pd.read_csv("data.csv")
|
47 |
data_analyzer = DataAnalyzer(data)
|
48 |
data_analyzer.show_eda()
|
49 |
+
LLM_summary(data)
|
50 |
|
51 |
data_analyzer.show_count_plots()
|
52 |
|
requirements.txt
CHANGED
@@ -11,4 +11,6 @@ litellm
|
|
11 |
streamlit_option_menu
|
12 |
scikit-learn
|
13 |
pytest
|
14 |
-
streamlit-modal
|
|
|
|
|
|
11 |
streamlit_option_menu
|
12 |
scikit-learn
|
13 |
pytest
|
14 |
+
streamlit-modal
|
15 |
+
reportlab
|
16 |
+
PyPDF2
|