pi194046 commited on
Commit
0a66a74
·
1 Parent(s): 141a839

adding changes for presentation creator

Browse files
Files changed (1) hide show
  1. app.py +105 -30
app.py CHANGED
@@ -90,33 +90,108 @@ else:
90
  # Display UUID in a non-editable text field
91
  st.text_input("Your UUID", value=uuid_from_js, disabled=True)
92
 
93
- uploaded_file = st.file_uploader("Upload your reviews CSV file", type=["csv"])
94
-
95
- if uploaded_file is not None:
96
- # Save uploaded file to FastAPI
97
- en1 = generate_unique_hash(uploaded_file.name, uuid_from_js)
98
- files = {"file": (en1, uploaded_file.getvalue(), "text/csv")}
99
- st.info("Calling model inference. Please wait...")
100
- response = requests.post(f"{BASE_URL}/upload/", files=files,headers=headers)
101
- print(response)
102
- if response.status_code == 200:
103
- st.info("Processing started. Please wait...")
104
-
105
- # Poll for completion
106
- while True:
107
- status_response = requests.get(f"{BASE_URL}/status/{en1}",headers=headers)
108
- if status_response.status_code == 200 and status_response.json()["status"] == "complete":
109
- st.success("File processed successfully.")
110
- download_response = requests.get(f"{BASE_URL}/download/{en1}",headers=headers)
111
-
112
- if download_response.status_code == 200:
113
- st.download_button(
114
- label="Download Processed File",
115
- data=download_response.content,
116
- file_name=f"processed_{en1}",
117
- mime="text/csv"
118
- )
119
- break
120
- time.sleep(2)
121
- else:
122
- st.error("Failed to upload file for processing.")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
90
  # Display UUID in a non-editable text field
91
  st.text_input("Your UUID", value=uuid_from_js, disabled=True)
92
 
93
+ # Define tabs
94
+ tab1, tab2 = st.tabs(["Review Analyzer", "Presentation Creator"])
95
+
96
+ with tab1:
97
+ st.header("Review Analyzer")
98
+
99
+ uploaded_file = st.file_uploader("Upload your reviews CSV file", type=["csv"],key=2)
100
+
101
+ if uploaded_file is not None:
102
+ en1 = generate_unique_hash(uploaded_file.name, uuid_from_js)
103
+ files = {"file": (en1, uploaded_file.getvalue(), "text/csv")}
104
+ st.info("Calling model inference. Please wait...")
105
+ response = requests.post(f"{BASE_URL}/upload/", files=files, headers=headers)
106
+
107
+ if response.status_code == 200:
108
+ st.info("Processing started. Please wait...")
109
+
110
+ # Poll for completion
111
+ while True:
112
+ status_response = requests.get(f"{BASE_URL}/status/{en1}", headers=headers)
113
+ if status_response.status_code == 200 and (status_response.json()["status"] == "complete" or status_response.json()["status"] == "error"):
114
+ if status_response.json()["status"] == "complete":
115
+ st.success("File processed successfully.")
116
+ download_response = requests.get(f"{BASE_URL}/download/{en1}", headers=headers)
117
+
118
+ if download_response.status_code == 200:
119
+ st.download_button(
120
+ label="Download Processed File",
121
+ data=download_response.content,
122
+ file_name=f"processed_{en1}",
123
+ mime="text/csv"
124
+ )
125
+ break
126
+ time.sleep(10)
127
+ else:
128
+ st.error("Failed to upload file for processing.")
129
+
130
+ with tab2:
131
+ st.header("Presentation Creator")
132
+
133
+ # Input URL for presentation creation
134
+ presentation_url = st.text_input("Enter the URL for the presentation content")
135
+
136
+ if presentation_url:
137
+ #unique_id = generate_unique_hash(presentation_url, str(uuid.uuid4()))
138
+ st.info("Creating presentation. Please wait...")
139
+
140
+ # Mock payload for processing the URL
141
+ payload = {"url": presentation_url, "id": uuid_from_js}
142
+ response = requests.post(f"{BASE_URL}/presentation_creator", json=payload, headers=headers)
143
+
144
+ if response.status_code == 200:
145
+ st.info("Processing started. Please wait...")
146
+ unique_id=response.json()["filename"]
147
+ # Poll for completion
148
+ while True:
149
+ status_response = requests.get(f"{BASE_URL}/status/{unique_id}", headers=headers)
150
+ if status_response.status_code == 200 and (status_response.json()["status"] == "complete" or status_response.json()["status"] == "error"):
151
+ if status_response.json()["status"] == "complete":
152
+ st.success("Presentation created successfully.")
153
+ download_response = requests.get(f"{BASE_URL}/download/{unique_id}", headers=headers)
154
+
155
+ if download_response.status_code == 200:
156
+ st.download_button(
157
+ label="Download Presentation File",
158
+ data=download_response.content,
159
+ file_name=f"presentation_{unique_id}.pptx",
160
+ mime="application/pdf"
161
+ )
162
+ break
163
+ time.sleep(10)
164
+ else:
165
+ st.error("Failed to create presentation.")
166
+
167
+ # uploaded_file = st.file_uploader("Upload your reviews CSV file", type=["csv"],key=1)
168
+
169
+ # if uploaded_file is not None:
170
+ # # Save uploaded file to FastAPI
171
+ # en1 = generate_unique_hash(uploaded_file.name, uuid_from_js)
172
+ # files = {"file": (en1, uploaded_file.getvalue(), "text/csv")}
173
+ # st.info("Calling model inference. Please wait...")
174
+ # response = requests.post(f"{BASE_URL}/upload/", files=files,headers=headers)
175
+ # print("response to file upload is ",response)
176
+ # if response.status_code == 200:
177
+ # st.info("Processing started. Please wait...")
178
+
179
+ # # Poll for completion
180
+ # while True:
181
+ # status_response = requests.get(f"{BASE_URL}/status/{en1}",headers=headers)
182
+ # if status_response.status_code == 200 and (status_response.json()["status"] == "complete" or status_response.json()["status"]=="error"):
183
+ # if status_response.json()["status"] == "complete":
184
+ # st.success("File processed successfully.")
185
+ # download_response = requests.get(f"{BASE_URL}/download/{en1}",headers=headers)
186
+
187
+ # if download_response.status_code == 200:
188
+ # st.download_button(
189
+ # label="Download Processed File",
190
+ # data=download_response.content,
191
+ # file_name=f"processed_{en1}",
192
+ # mime="text/csv"
193
+ # )
194
+ # break
195
+ # time.sleep(10)
196
+ # else:
197
+ # st.error("Failed to upload file for processing.")