iohanngrig commited on
Commit
a888ac6
·
verified ·
1 Parent(s): d2fd8e4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -32
app.py CHANGED
@@ -6,6 +6,18 @@ import pandas as pd
6
  import io
7
  from openai import OpenAI
8
 
 
 
 
 
 
 
 
 
 
 
 
 
9
  # Initialize OpenAI client
10
  client = OpenAI()
11
 
@@ -28,39 +40,14 @@ def main():
28
 
29
  # Set up the page
30
  st.set_page_config(page_title="Physics Instructor", page_icon="⚖️")
31
- st.title("Physics Instructor")
32
  st.header("Feynman AI (GPT based)")
33
- st.sidebar.title("Physics Instructor")
34
- #st.sidebar.divider()
35
-
36
- # File uploader for CSV, XLS, XLSX
37
- uploaded_file = st.file_uploader("Upload your file", type=["csv", "xls", "xlsx"])
38
-
39
- if uploaded_file is not None:
40
- # Determine the file type
41
- file_type = uploaded_file.type
42
- try:
43
- # Read the file into a Pandas DataFrame
44
- if file_type == "text/csv":
45
- df = pd.read_csv(uploaded_file)
46
- elif file_type in ["application/vnd.ms-excel",
47
- "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"]:
48
- df = pd.read_excel(uploaded_file)
49
-
50
- # Convert DataFrame to JSON
51
- json_str = df.to_json(orient='records', indent=4)
52
- file_stream = io.BytesIO(json_str.encode())
53
-
54
- # Upload JSON data to OpenAI and store the file ID
55
- file_response = client.files.create(file=file_stream, purpose='answers')
56
- st.session_state.file_id = file_response.id
57
- st.success("File uploaded successfully to OpenAI!")
58
-
59
- # Optional: Display and Download JSON
60
- st.text_area("JSON Output", json_str, height=300)
61
- st.download_button(label="Download JSON", data=json_str, file_name="converted.json", mime="application/json")
62
- except Exception as e:
63
- st.error(f"An error occurred: {e}")
64
 
65
  # Initialize OpenAI assistant
66
  if "assistant" not in st.session_state:
 
6
  import io
7
  from openai import OpenAI
8
 
9
+ css_code = """
10
+ <style>
11
+ section[data-testid="stSidebar"] > div > div:nth-child(2) {
12
+ padding-top: 0.75rem !important;
13
+ }
14
+
15
+ section.main > div {
16
+ padding-top: 64px;
17
+ }
18
+ </style>
19
+ """
20
+
21
  # Initialize OpenAI client
22
  client = OpenAI()
23
 
 
40
 
41
  # Set up the page
42
  st.set_page_config(page_title="Physics Instructor", page_icon="⚖️")
 
43
  st.header("Feynman AI (GPT based)")
44
+ #st.title("Physics Instructor")
45
+ st.markdown(css_code, unsafe_allow_html=True)
46
+ with st.sidebar:
47
+ st.image("feynman.jpg")
48
+ st.write("---")
49
+ st.title("Physics Instructor")
50
+ st.write("---")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
51
 
52
  # Initialize OpenAI assistant
53
  if "assistant" not in st.session_state: