Spaces:
Configuration error
Configuration error
update
Browse files- Home.py +0 -93
- app.py +176 -0
- pages/Help.py +0 -68
Home.py
DELETED
@@ -1,93 +0,0 @@
|
|
1 |
-
import streamlit as st
|
2 |
-
import pandas as pd
|
3 |
-
from langchain.agents import create_csv_agent
|
4 |
-
from langchain.llms import OpenAI
|
5 |
-
import time
|
6 |
-
# Set Streamlit page configuration
|
7 |
-
st.set_page_config(page_title='CSV Processing',
|
8 |
-
page_icon=":memo:",
|
9 |
-
layout='wide',
|
10 |
-
initial_sidebar_state='collapsed')
|
11 |
-
|
12 |
-
# Set CSS properties for HTML components
|
13 |
-
st.markdown("""
|
14 |
-
<style>
|
15 |
-
body {
|
16 |
-
color: #fff;
|
17 |
-
background-color: #4f8bf9;
|
18 |
-
}
|
19 |
-
h1, h2 {
|
20 |
-
color: #ffdd00;
|
21 |
-
}
|
22 |
-
</style>
|
23 |
-
""", unsafe_allow_html=True)
|
24 |
-
|
25 |
-
hide_style='''
|
26 |
-
<style>
|
27 |
-
#MainMenu {visibility:hidden;}
|
28 |
-
footer {visibility:hidden;}
|
29 |
-
.css-hi6a2p {padding-top: 0rem;}
|
30 |
-
head {visibility:hidden;}
|
31 |
-
</style>
|
32 |
-
'''
|
33 |
-
st.markdown("""
|
34 |
-
<h1 style='text-align: center; color: #ffdd00;'>XLS Office Documents Analysis with ChatGPT4 NLP Model</h1>
|
35 |
-
""", unsafe_allow_html=True)
|
36 |
-
#st.title('XLS Office Documents Analysis with ChatGPT4 NLP Model')
|
37 |
-
|
38 |
-
def load_data(file):
|
39 |
-
df = pd.read_excel(file, engine='openpyxl')
|
40 |
-
df.to_csv('data.csv', index=False) # Convert XLS to CSV
|
41 |
-
return 'data.csv'
|
42 |
-
|
43 |
-
def initialize_agent(file, openai_api_key):
|
44 |
-
agent = create_csv_agent(OpenAI(temperature=0, openai_api_key=openai_api_key), file, verbose=True)
|
45 |
-
return agent
|
46 |
-
|
47 |
-
uploaded_file = st.file_uploader("Upload XLS", type=['xlsx'])
|
48 |
-
st.markdown(hide_style, unsafe_allow_html=True)
|
49 |
-
|
50 |
-
openai_api_key = st.sidebar.text_input('OpenAI API Key', type="password")
|
51 |
-
|
52 |
-
# Pre-defined question examples
|
53 |
-
question_examples = [
|
54 |
-
"how many rows are there?",
|
55 |
-
"how many people are female?",
|
56 |
-
"how many people have stayed more than 3 years in the city?",
|
57 |
-
"how many people have stayed more than 3 years in the city and are female?",
|
58 |
-
"Are there more males or females?",
|
59 |
-
"What are the column names?",
|
60 |
-
"What is the average age?",
|
61 |
-
"Which country appears the most and how many times does it appear?",
|
62 |
-
"What is the ratio of males to females?"
|
63 |
-
# Add more examples as needed
|
64 |
-
]
|
65 |
-
|
66 |
-
# Dropdown select box for question examples
|
67 |
-
selected_example = st.selectbox('Choose a question example:', question_examples)
|
68 |
-
|
69 |
-
# Pre-populate the question field with the selected example
|
70 |
-
question = st.text_input('Enter your question:', value=selected_example)
|
71 |
-
|
72 |
-
if not openai_api_key or not openai_api_key.startswith('sk-'):
|
73 |
-
st.warning('Please enter your OpenAI API key!', icon='⚠️')
|
74 |
-
else:
|
75 |
-
if uploaded_file is not None:
|
76 |
-
# Create a progress bar
|
77 |
-
#progress_bar = st.progress(0)
|
78 |
-
#progress_bar.progress(25) # Start the progress at 25%
|
79 |
-
|
80 |
-
csv_file = load_data(uploaded_file) # Now the uploaded file is an XLS file
|
81 |
-
#progress_bar.progress(50) # Update the progress to 50%
|
82 |
-
|
83 |
-
agent = initialize_agent(csv_file, openai_api_key)
|
84 |
-
#progress_bar.progress(100) # Complete the progress bar
|
85 |
-
|
86 |
-
if question:
|
87 |
-
response = agent.run(question)
|
88 |
-
with st.spinner('Wait for it...'):
|
89 |
-
time.sleep(5)
|
90 |
-
st.success('Done!')
|
91 |
-
#st.markdown(f'**Response:** {response}')
|
92 |
-
st.markdown(f'<div style="color: red; font-size: 24px; text-align: center;">The Answer is:{response}</div>',unsafe_allow_html=True)
|
93 |
-
|
|
|
|
|
|
|
|
|
|
|
|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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import pandas as pd
|
3 |
+
from langchain.agents import create_csv_agent
|
4 |
+
from langchain.llms import OpenAI
|
5 |
+
import time
|
6 |
+
from streamlit_option_menu import option_menu
|
7 |
+
|
8 |
+
# Set Streamlit page configuration
|
9 |
+
st.set_page_config(page_title='CSV Processing',
|
10 |
+
page_icon=":memo:",
|
11 |
+
layout='wide',
|
12 |
+
initial_sidebar_state='collapsed')
|
13 |
+
|
14 |
+
# Set CSS properties for HTML components
|
15 |
+
st.markdown("""
|
16 |
+
<style>
|
17 |
+
body {
|
18 |
+
color: #fff;
|
19 |
+
background-color: #4f8bf9;
|
20 |
+
}
|
21 |
+
h1, h2 {
|
22 |
+
color: #ffdd00;
|
23 |
+
}
|
24 |
+
</style>
|
25 |
+
""", unsafe_allow_html=True)
|
26 |
+
|
27 |
+
hide_style='''
|
28 |
+
<style>
|
29 |
+
#MainMenu {visibility:hidden;}
|
30 |
+
footer {visibility:hidden;}
|
31 |
+
.css-hi6a2p {padding-top: 0rem;}
|
32 |
+
head {visibility:hidden;}
|
33 |
+
</style>
|
34 |
+
'''
|
35 |
+
st.markdown("""
|
36 |
+
<h1 style='text-align: center; color: #ffdd00;'>XLS Office Documents Analysis with ChatGPT4 NLP Model</h1>
|
37 |
+
""", unsafe_allow_html=True)
|
38 |
+
#st.title('XLS Office Documents Analysis with ChatGPT4 NLP Model')
|
39 |
+
# 1. as sidebar menu
|
40 |
+
with st.sidebar:
|
41 |
+
selected = option_menu("Main Menu", ["Home", 'Help'],
|
42 |
+
icons=['house', 'gear'], menu_icon="cast", default_index=0)
|
43 |
+
selected
|
44 |
+
|
45 |
+
if selected=="Help":
|
46 |
+
# st.title("Help")
|
47 |
+
# Import required libraries
|
48 |
+
import streamlit as st
|
49 |
+
|
50 |
+
# Set Streamlit page configuration
|
51 |
+
#st.set_page_config(page_title='Help - XLS Office Documents Analysis with ChatGPT4 NLP Model',
|
52 |
+
# page_icon=":memo:",
|
53 |
+
# layout='wide',
|
54 |
+
# initial_sidebar_state='collapsed')
|
55 |
+
|
56 |
+
# Set CSS properties for HTML components
|
57 |
+
st.markdown("""
|
58 |
+
<style>
|
59 |
+
body {
|
60 |
+
color: #fff;
|
61 |
+
background-color: #4f8bf9;
|
62 |
+
}
|
63 |
+
h1, h2 {
|
64 |
+
color: #ffdd00;
|
65 |
+
}
|
66 |
+
</style>
|
67 |
+
""", unsafe_allow_html=True)
|
68 |
+
|
69 |
+
# Use HTML in markdown to center align the title
|
70 |
+
# st.markdown("""
|
71 |
+
# <h1 style='text-align: center; color: #ffdd00;'>Help Document for XLS Office Documents Analysis with ChatGPT4 NLP Model</h1>
|
72 |
+
# """, unsafe_allow_html=True)
|
73 |
+
|
74 |
+
# Display authorship details
|
75 |
+
st.markdown("""
|
76 |
+
## Developed by Falah.G.Salieh
|
77 |
+
* AI Developer
|
78 |
+
* Specialized in Natural Language Processing
|
79 |
+
""", unsafe_allow_html=True)
|
80 |
+
|
81 |
+
# Display help content
|
82 |
+
st.markdown("""
|
83 |
+
## Getting Started
|
84 |
+
|
85 |
+
This project aims to ...
|
86 |
+
|
87 |
+
Here's how to use this app:
|
88 |
+
|
89 |
+
1. Step 1: ...
|
90 |
+
2. Step 2: ...
|
91 |
+
3. Step 3: ...
|
92 |
+
|
93 |
+
Please note that ...
|
94 |
+
|
95 |
+
### Uploading Your XLS File
|
96 |
+
|
97 |
+
To upload your XLS file, ...
|
98 |
+
|
99 |
+
### Using the ChatGPT-4 NLP Model
|
100 |
+
|
101 |
+
To use the ChatGPT-4 NLP model, ...
|
102 |
+
|
103 |
+
### Understanding the Results
|
104 |
+
|
105 |
+
When you receive the results, ...
|
106 |
+
|
107 |
+
### Troubleshooting
|
108 |
+
|
109 |
+
If you encounter any problems, ...
|
110 |
+
|
111 |
+
## Contact
|
112 |
+
|
113 |
+
If you have any questions, feel free to ...
|
114 |
+
""", unsafe_allow_html=True)
|
115 |
+
|
116 |
+
|
117 |
+
#-----------------
|
118 |
+
if selected=="Home":
|
119 |
+
#st.title("home")
|
120 |
+
|
121 |
+
def load_data(file):
|
122 |
+
df = pd.read_excel(file, engine='openpyxl')
|
123 |
+
df.to_csv('data.csv', index=False) # Convert XLS to CSV
|
124 |
+
return 'data.csv'
|
125 |
+
|
126 |
+
def initialize_agent(file, openai_api_key):
|
127 |
+
agent = create_csv_agent(OpenAI(temperature=0, openai_api_key=openai_api_key), file, verbose=True)
|
128 |
+
return agent
|
129 |
+
|
130 |
+
uploaded_file = st.file_uploader("Upload XLS", type=['xlsx'])
|
131 |
+
st.markdown(hide_style, unsafe_allow_html=True)
|
132 |
+
|
133 |
+
openai_api_key = st.sidebar.text_input('OpenAI API Key', type="password")
|
134 |
+
|
135 |
+
# Pre-defined question examples
|
136 |
+
question_examples = [
|
137 |
+
"how many rows are there?",
|
138 |
+
"how many people are female?",
|
139 |
+
"how many people have stayed more than 3 years in the city?",
|
140 |
+
"how many people have stayed more than 3 years in the city and are female?",
|
141 |
+
"Are there more males or females?",
|
142 |
+
"What are the column names?",
|
143 |
+
"What is the average age?",
|
144 |
+
"Which country appears the most and how many times does it appear?",
|
145 |
+
"What is the ratio of males to females?"
|
146 |
+
# Add more examples as needed
|
147 |
+
]
|
148 |
+
|
149 |
+
# Dropdown select box for question examples
|
150 |
+
selected_example = st.selectbox('Choose a question example:', question_examples)
|
151 |
+
|
152 |
+
# Pre-populate the question field with the selected example
|
153 |
+
question = st.text_input('Enter your question:', value=selected_example)
|
154 |
+
|
155 |
+
if not openai_api_key or not openai_api_key.startswith('sk-'):
|
156 |
+
st.warning('Please enter your OpenAI API key!', icon='⚠️')
|
157 |
+
else:
|
158 |
+
if uploaded_file is not None:
|
159 |
+
# Create a progress bar
|
160 |
+
#progress_bar = st.progress(0)
|
161 |
+
#progress_bar.progress(25) # Start the progress at 25%
|
162 |
+
|
163 |
+
csv_file = load_data(uploaded_file) # Now the uploaded file is an XLS file
|
164 |
+
#progress_bar.progress(50) # Update the progress to 50%
|
165 |
+
|
166 |
+
agent = initialize_agent(csv_file, openai_api_key)
|
167 |
+
#progress_bar.progress(100) # Complete the progress bar
|
168 |
+
|
169 |
+
if question:
|
170 |
+
response = agent.run(question)
|
171 |
+
with st.spinner('Wait for it...'):
|
172 |
+
time.sleep(5)
|
173 |
+
st.success('Done!')
|
174 |
+
#st.markdown(f'**Response:** {response}')
|
175 |
+
st.markdown(f'<div style="color: red; font-size: 24px; text-align: center;">The Answer is:{response}</div>',unsafe_allow_html=True)
|
176 |
+
|
pages/Help.py
DELETED
@@ -1,68 +0,0 @@
|
|
1 |
-
# Import required libraries
|
2 |
-
import streamlit as st
|
3 |
-
|
4 |
-
# Set Streamlit page configuration
|
5 |
-
st.set_page_config(page_title='Help - XLS Office Documents Analysis with ChatGPT4 NLP Model',
|
6 |
-
page_icon=":memo:",
|
7 |
-
layout='wide',
|
8 |
-
initial_sidebar_state='collapsed')
|
9 |
-
|
10 |
-
# Set CSS properties for HTML components
|
11 |
-
st.markdown("""
|
12 |
-
<style>
|
13 |
-
body {
|
14 |
-
color: #fff;
|
15 |
-
background-color: #4f8bf9;
|
16 |
-
}
|
17 |
-
h1, h2 {
|
18 |
-
color: #ffdd00;
|
19 |
-
}
|
20 |
-
</style>
|
21 |
-
""", unsafe_allow_html=True)
|
22 |
-
|
23 |
-
# Use HTML in markdown to center align the title
|
24 |
-
st.markdown("""
|
25 |
-
<h1 style='text-align: center; color: #ffdd00;'>Help Document for XLS Office Documents Analysis with ChatGPT4 NLP Model</h1>
|
26 |
-
""", unsafe_allow_html=True)
|
27 |
-
|
28 |
-
# Display authorship details
|
29 |
-
st.markdown("""
|
30 |
-
## Developed by Falah.G.Salieh
|
31 |
-
* AI Developer
|
32 |
-
* Specialized in Natural Language Processing
|
33 |
-
""", unsafe_allow_html=True)
|
34 |
-
|
35 |
-
# Display help content
|
36 |
-
st.markdown("""
|
37 |
-
## Getting Started
|
38 |
-
|
39 |
-
This project aims to ...
|
40 |
-
|
41 |
-
Here's how to use this app:
|
42 |
-
|
43 |
-
1. Step 1: ...
|
44 |
-
2. Step 2: ...
|
45 |
-
3. Step 3: ...
|
46 |
-
|
47 |
-
Please note that ...
|
48 |
-
|
49 |
-
### Uploading Your XLS File
|
50 |
-
|
51 |
-
To upload your XLS file, ...
|
52 |
-
|
53 |
-
### Using the ChatGPT-4 NLP Model
|
54 |
-
|
55 |
-
To use the ChatGPT-4 NLP model, ...
|
56 |
-
|
57 |
-
### Understanding the Results
|
58 |
-
|
59 |
-
When you receive the results, ...
|
60 |
-
|
61 |
-
### Troubleshooting
|
62 |
-
|
63 |
-
If you encounter any problems, ...
|
64 |
-
|
65 |
-
## Contact
|
66 |
-
|
67 |
-
If you have any questions, feel free to ...
|
68 |
-
""", unsafe_allow_html=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|