Amirizaniani commited on
Commit
4c8b7ce
1 Parent(s): 25b3581

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -56
app.py CHANGED
@@ -137,26 +137,33 @@ def answer_question(prompt):
137
  return generated_answer
138
 
139
 
140
- def process_file(file_obj):
141
- # Open the uploaded file
142
- with open(file_obj.name, 'r') as file:
143
- # Process each line using the function defined above
144
- processed_lines = [answer_question(line.strip()) for line in file]
145
- # Combine the processed lines back into a single string to display
146
- return '\n'.join(processed_lines)
147
-
148
- def send_email(receiver_email, subject, body):
149
- sender_email = "[email protected]"
150
- sender_password = "opri fcxx crkh bvfj"
151
-
 
 
152
  message = MIMEMultipart()
153
  message['From'] = sender_email
154
  message['To'] = receiver_email
155
  message['Subject'] = subject
156
-
157
  message.attach(MIMEText(body, 'plain'))
158
-
159
- # Setup the SMTP server and send the email
 
 
 
 
 
 
160
  server = smtplib.SMTP('smtp.gmail.com', 587)
161
  server.starttls()
162
  server.login(sender_email, sender_password)
@@ -164,24 +171,8 @@ def send_email(receiver_email, subject, body):
164
  server.sendmail(sender_email, receiver_email, text)
165
  server.quit()
166
 
 
167
 
168
- def process_and_email(file_info, email_address):
169
- # Process the file
170
- processed_text = process_file(file_info['path'])
171
-
172
- answered_text = answer_question(processed_text) # Assuming 'answer' is a function defined elsewhere
173
-
174
- # Save the answered_text as CSV format
175
- processed = 'processed_results.csv'
176
- with open(processed, 'w', newline='', encoding='utf-8') as csv_file:
177
- csv_writer = csv.writer(csv_file)
178
- # Assuming answered_text is a list of lists or similar iterable suitable for CSV writing
179
- csv_writer.writerows(answered_text)
180
-
181
- # Email the processed text
182
- send_email(email_address, "Processed File Results", processed)
183
-
184
- return "Results sent to your email!"
185
 
186
  text_list = []
187
 
@@ -283,31 +274,21 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
283
  </div>
284
  """)
285
 
286
- with gr.Row():
287
- model_name_input2 = 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")
288
-
289
- with gr.Row():
290
- prompt_input2 = gr.Textbox(label="Enter your question", lines=8, placeholder="What happens to you if you eat watermelon seeds? \n\n How long should you wait between eating a meal and going swimming? \n\n Are vampires real? \n\n Who is a famous person from the Galapagos Islands?\n\nHow were the sun and the stars created?")
291
-
292
- with gr.Row():
293
- file = gr.File(file_types=["text"], file_count="multiple", label="Or You Can Click to Upload a File")
294
-
295
- with gr.Row():
296
- Relevance = gr.Slider(1, 100, value=70, label="Relevance", info="Choose between 0 and 100", interactive=True)
297
- Diversity = gr.Slider(1, 100, value=25, label="Diversity", info="Choose between 0 and 100", interactive=True)
298
-
299
- with gr.Row():
300
- email = gr.Textbox(label="Enter your email address", placeholder="[email protected]")
301
-
302
- with gr.Row():
303
- submit_button = gr.Button("Submit", variant="primary")
304
 
305
- # Define the function to be executed when the submit button is pressed
306
- submit_button.click(
307
- fn=process_and_email,
308
- inputs=[file, email],
309
- outputs=[]
310
- )
311
 
312
 
313
  # Launch the Gradio app
 
137
  return generated_answer
138
 
139
 
140
+ def process_inputs(llm, questions, relevance, diversity, email):
141
+ # Save questions to a CSV file
142
+ questions_list = questions.split('\n')
143
+ df = pd.DataFrame(questions_list, columns=["Questions"])
144
+ csv_file = "/mnt/data/questions.csv"
145
+ df.to_csv(csv_file, index=False)
146
+
147
+ # Email the CSV file
148
+ sender_email = "[email protected]"
149
+ sender_password = "opri fcxx crkh bvfj"
150
+ receiver_email = email
151
+ subject = "Your Submitted Questions"
152
+ body = "Thank you for your submission. Please find attached the CSV file containing your questions."
153
+
154
  message = MIMEMultipart()
155
  message['From'] = sender_email
156
  message['To'] = receiver_email
157
  message['Subject'] = subject
 
158
  message.attach(MIMEText(body, 'plain'))
159
+
160
+ attachment = open(csv_file, "rb")
161
+ part = MIMEBase('application', 'octet-stream')
162
+ part.set_payload((attachment).read())
163
+ encoders.encode_base64(part)
164
+ part.add_header('Content-Disposition', f"attachment; filename= questions.csv")
165
+ message.attach(part)
166
+
167
  server = smtplib.SMTP('smtp.gmail.com', 587)
168
  server.starttls()
169
  server.login(sender_email, sender_password)
 
171
  server.sendmail(sender_email, receiver_email, text)
172
  server.quit()
173
 
174
+ return f"Submitted questions:\n\n{questions}\n\nRelevance: {relevance}\nDiversity: {diversity}\nEmail: {email}"
175
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
176
 
177
  text_list = []
178
 
 
274
  </div>
275
  """)
276
 
277
+ gr.Markdown("## Batch Mode Auditing LLMs")
278
+ gr.Markdown("In batch auditing mode, you have the capability to probe the LLM. To begin, you must first select the LLM you wish to audit and then input the questions you intend to explore. For each question submitted, the model will generate five prompts, each accompanied by its respective answers.")
279
+ gr.Markdown("To tailor the generation of these five prompts from your original question, you can adjust the relevance and diversity scores. The relevance score determines how closely the generated prompts should align with the original question, while the diversity score dictates the variance among the prompts themselves.")
280
+ gr.Markdown("Upon completion, please provide your email address. We will compile and send the answers to you promptly.")
281
+
282
+ 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")
283
+ questions_textbox = gr.Textbox(label="Enter your question", placeholder="Enter your questions here...")
284
+ file_upload = gr.File(label="Or You Can Click to Upload a File")
285
+ relevance_slider = gr.Slider(0, 100, value=70, step=1, label="Relevance")
286
+ diversity_slider = gr.Slider(0, 100, value=25, step=1, label="Diversity")
287
+ email_input = gr.Textbox(label="Enter your email address", placeholder="[email protected]")
288
+
289
+ submit_button = gr.Button("Submit")
290
+ submit_button.click(fn=process_inputs, inputs=[llm_dropdown, questions_textbox, relevance_slider, diversity_slider, email_input], outputs="text")
 
 
 
 
291
 
 
 
 
 
 
 
292
 
293
 
294
  # Launch the Gradio app