acecalisto3 commited on
Commit
0f32cbe
·
verified ·
1 Parent(s): 72e8f70

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -22
app.py CHANGED
@@ -182,35 +182,50 @@ def respond(
182
  )
183
  return response
184
 
 
 
 
 
 
 
 
 
 
 
 
 
 
185
  # Create Gradio interface
186
  def chat_interface(message, system_message, max_tokens, temperature, top_p, storage_location, url1, url2, scrape_interval, content_type):
187
  global history
188
  response = respond(message, history, system_message, max_tokens, temperature, top_p)
189
  history.append((message, response))
190
- handle_input(storage_location, url1, url2, scrape_interval, content_type)
191
  return history, ""
192
 
193
- demo = gr.Interface(
194
- fn=chat_interface,
195
- inputs=[
196
- gr.Textbox(label="Message"),
197
- gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
198
- gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
199
- gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
200
- gr.Slider(minimum=0.1, maximum=1.0, value=0.95, step=0.05, label="Top-p (nucleus sampling)"),
201
- gr.Textbox(value=default_file_path, label="Storage Location"),
202
- gr.Textbox(value="https://www.culver.k12.in.us/", label="URL 1"),
203
- gr.Textbox(value="https://www.facebook.com/CulverCommunitySchools", label="URL 2"),
204
- gr.Slider(minimum=1, maximum=60, value=5, step=1, label="Scrape Interval (minutes)"),
205
- gr.Radio(choices=["text", "media", "both"], value="text", label="Content Type"),
206
- ],
207
- outputs=[
208
- gr.Chatbot(label="Chat History"),
209
- gr.Textbox(label="Response")
210
- ],
211
- title="Culvers Site Monitor and Chatbot",
212
- description="Monitor changes on Culvers' websites and log them into a CSV file. Also, chat with a friendly chatbot."
213
- )
 
 
 
214
 
215
  if __name__ == "__main__":
216
  demo.launch()
 
182
  )
183
  return response
184
 
185
+ # Function to start scraping
186
+ def start_scraping(storage_location, url1, url2, scrape_interval, content_type):
187
+ handle_input(storage_location, url1, url2, scrape_interval, content_type)
188
+ return f"Started scraping {url1} and {url2} every {scrape_interval} minutes."
189
+
190
+ # Function to display CSV content
191
+ def display_csv(storage_location):
192
+ if os.path.exists(storage_location):
193
+ with open(storage_location, "r") as file:
194
+ return file.read()
195
+ else:
196
+ return "No data available."
197
+
198
  # Create Gradio interface
199
  def chat_interface(message, system_message, max_tokens, temperature, top_p, storage_location, url1, url2, scrape_interval, content_type):
200
  global history
201
  response = respond(message, history, system_message, max_tokens, temperature, top_p)
202
  history.append((message, response))
 
203
  return history, ""
204
 
205
+ demo = gr.Blocks()
206
+
207
+ with demo:
208
+ with gr.Row():
209
+ with gr.Column():
210
+ message = gr.Textbox(label="Message")
211
+ system_message = gr.Textbox(value="You are a friendly Chatbot.", label="System message")
212
+ max_tokens = gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens")
213
+ temperature = gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature")
214
+ top_p = gr.Slider(minimum=0.1, maximum=1.0, value=0.95, step=0.05, label="Top-p (nucleus sampling)")
215
+ storage_location = gr.Textbox(value=default_file_path, label="Storage Location")
216
+ url1 = gr.Textbox(value="https://www.culver.k12.in.us/", label="URL 1")
217
+ url2 = gr.Textbox(value="https://www.facebook.com/CulverCommunitySchools", label="URL 2")
218
+ scrape_interval = gr.Slider(minimum=1, maximum=60, value=5, step=1, label="Scrape Interval (minutes)")
219
+ content_type = gr.Radio(choices=["text", "media", "both"], value="text", label="Content Type")
220
+ start_button = gr.Button("Start Scraping")
221
+ csv_output = gr.Textbox(label="CSV Output", interactive=False)
222
+
223
+ with gr.Column():
224
+ chat_history = gr.Chatbot(label="Chat History")
225
+ response_box = gr.Textbox(label="Response")
226
+
227
+ start_button.click(start_scraping, inputs=[storage_location, url1, url2, scrape_interval, content_type], outputs=csv_output)
228
+ message.submit(chat_interface, inputs=[message, system_message, max_tokens, temperature, top_p, storage_location, url1, url2, scrape_interval, content_type], outputs=[chat_history, response_box])
229
 
230
  if __name__ == "__main__":
231
  demo.launch()