Spaces:
Runtime error
Runtime error
Update app.py
Browse files
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.
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
gr.
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
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()
|