Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -147,64 +147,29 @@ def answer_question(prompt):
|
|
147 |
return generated_answer
|
148 |
|
149 |
|
150 |
-
def process_inputs(llm, file, relevance, diversity
|
151 |
# Check if file is uploaded
|
152 |
if file is not None:
|
153 |
# Read questions from the uploaded Excel file
|
154 |
try:
|
155 |
df = pd.read_excel(file.name, engine='openpyxl')
|
156 |
except Exception as e:
|
157 |
-
return f"Failed to read Excel file: {e}"
|
158 |
|
159 |
# Ensure that there is only one column in the file
|
160 |
if df.shape[1] != 1:
|
161 |
-
return "The uploaded file must contain only one column of questions."
|
162 |
|
163 |
questions_list = df.iloc[:, 0].tolist()
|
164 |
else:
|
165 |
-
return "No questions provided."
|
166 |
-
|
167 |
-
# Save questions to a CSV file
|
168 |
-
df = pd.DataFrame(questions_list, columns=["Questions"])
|
169 |
-
csv_file = "questions.csv"
|
170 |
-
df.to_csv(csv_file, index=False)
|
171 |
-
|
172 |
-
# Check network connectivity to the custom port
|
173 |
-
try:
|
174 |
-
socket.create_connection(("your.relay.server", 25), timeout=10) # Replace with your relay server and port
|
175 |
-
except OSError:
|
176 |
-
return "Network is unreachable. Unable to send email."
|
177 |
-
|
178 |
-
# Email the CSV file
|
179 |
-
sender_email = "auditllms@gmail.com"
|
180 |
-
sender_password = "opri fcxx crkh bvfj"
|
181 |
-
receiver_email = email
|
182 |
-
subject = "Your Submitted Questions"
|
183 |
-
body = "Thank you for your submission. Please find attached the CSV file containing your questions."
|
184 |
-
|
185 |
-
message = MIMEMultipart()
|
186 |
-
message['From'] = sender_email
|
187 |
-
message['To'] = receiver_email
|
188 |
-
message['Subject'] = subject
|
189 |
-
message.attach(MIMEText(body, 'plain'))
|
190 |
-
|
191 |
-
with open(csv_file, "rb") as attachment:
|
192 |
-
part = MIMEBase('application', 'octet-stream')
|
193 |
-
part.set_payload(attachment.read())
|
194 |
-
encoders.encode_base64(part)
|
195 |
-
part.add_header('Content-Disposition', f"attachment; filename= questions.csv")
|
196 |
-
message.attach(part)
|
197 |
-
|
198 |
-
try:
|
199 |
-
with smtplib.SMTP('your.relay.server', 25) as server: # Use your relay server and custom port
|
200 |
-
server.starttls() # Upgrade the connection to a secure encrypted SSL/TLS connection
|
201 |
-
server.login(sender_email, sender_password)
|
202 |
-
server.sendmail(sender_email, receiver_email, message.as_string())
|
203 |
-
except Exception as e:
|
204 |
-
return f"Failed to send email: {e}"
|
205 |
-
|
206 |
-
return "Submitted"
|
207 |
|
|
|
|
|
|
|
|
|
|
|
|
|
208 |
|
209 |
|
210 |
text_list = []
|
@@ -313,15 +278,19 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
|
313 |
gr.Markdown("Upon completion, please provide your email address. We will compile and send the answers to you promptly.")
|
314 |
|
315 |
llm_dropdown = gr.Dropdown([("Llama", "TheBloke/Llama-2-7B-Chat-GGML"), ("Falcon", "TheBloke/Falcon-180B-Chat-GGUF"), ("Zephyr", "TheBloke/zephyr-quiklang-3b-4K-GGUF"), ("Vicuna", "TheBloke/vicuna-33B-GGUF"), ("Claude", "TheBloke/claude2-alpaca-13B-GGUF"), ("Alpaca", "TheBloke/LeoScorpius-GreenNode-Alpaca-7B-v1-GGUF")], label="Large Language Model")
|
316 |
-
file_upload = gr.File(label="Upload a File with Questions", file_types=["
|
317 |
relevance_slider = gr.Slider(0, 100, value=70, step=1, label="Relevance")
|
318 |
diversity_slider = gr.Slider(0, 100, value=25, step=1, label="Diversity")
|
319 |
-
email_input = gr.Textbox(label="Enter your email address", placeholder="name@example.com")
|
320 |
|
321 |
submit_button = gr.Button("Submit")
|
322 |
output_textbox = gr.Textbox(label="Output")
|
323 |
-
|
|
|
|
|
|
|
|
|
324 |
|
|
|
325 |
|
326 |
|
327 |
# Launch the Gradio app
|
|
|
147 |
return generated_answer
|
148 |
|
149 |
|
150 |
+
def process_inputs(llm, file, relevance, diversity):
|
151 |
# Check if file is uploaded
|
152 |
if file is not None:
|
153 |
# Read questions from the uploaded Excel file
|
154 |
try:
|
155 |
df = pd.read_excel(file.name, engine='openpyxl')
|
156 |
except Exception as e:
|
157 |
+
return f"Failed to read Excel file: {e}", None
|
158 |
|
159 |
# Ensure that there is only one column in the file
|
160 |
if df.shape[1] != 1:
|
161 |
+
return "The uploaded file must contain only one column of questions.", None
|
162 |
|
163 |
questions_list = df.iloc[:, 0].tolist()
|
164 |
else:
|
165 |
+
return "No questions provided.", None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
166 |
|
167 |
+
# Save questions to a new Excel file
|
168 |
+
output_df = pd.DataFrame(questions_list, columns=["Questions"])
|
169 |
+
output_file = "processed_questions.xlsx"
|
170 |
+
output_df.to_excel(output_file, index=False)
|
171 |
+
|
172 |
+
return "Processing complete. Download the file below.", output_file
|
173 |
|
174 |
|
175 |
text_list = []
|
|
|
278 |
gr.Markdown("Upon completion, please provide your email address. We will compile and send the answers to you promptly.")
|
279 |
|
280 |
llm_dropdown = gr.Dropdown([("Llama", "TheBloke/Llama-2-7B-Chat-GGML"), ("Falcon", "TheBloke/Falcon-180B-Chat-GGUF"), ("Zephyr", "TheBloke/zephyr-quiklang-3b-4K-GGUF"), ("Vicuna", "TheBloke/vicuna-33B-GGUF"), ("Claude", "TheBloke/claude2-alpaca-13B-GGUF"), ("Alpaca", "TheBloke/LeoScorpius-GreenNode-Alpaca-7B-v1-GGUF")], label="Large Language Model")
|
281 |
+
file_upload = gr.File(label="Upload a File with Questions", file_types=["xlsx"])
|
282 |
relevance_slider = gr.Slider(0, 100, value=70, step=1, label="Relevance")
|
283 |
diversity_slider = gr.Slider(0, 100, value=25, step=1, label="Diversity")
|
|
|
284 |
|
285 |
submit_button = gr.Button("Submit")
|
286 |
output_textbox = gr.Textbox(label="Output")
|
287 |
+
download_button = gr.File(label="Download Processed File")
|
288 |
+
|
289 |
+
def on_submit(llm, file, relevance, diversity):
|
290 |
+
result, output_file = process_inputs(llm, file, relevance, diversity)
|
291 |
+
return result, output_file
|
292 |
|
293 |
+
submit_button.click(fn=on_submit, inputs=[llm_dropdown, file_upload, relevance_slider, diversity_slider], outputs=[output_textbox, download_button])
|
294 |
|
295 |
|
296 |
# Launch the Gradio app
|