Update app.py
Browse files
app.py
CHANGED
@@ -143,6 +143,10 @@ def process_webpage(url):
|
|
143 |
# Fetch and parse webpage
|
144 |
response = requests.get(url).text
|
145 |
soup = BeautifulSoup(response, "html.parser")
|
|
|
|
|
|
|
|
|
146 |
html_content = str(soup.prettify())
|
147 |
|
148 |
for script in soup(["script", "style"]):
|
@@ -169,7 +173,7 @@ def process_webpage(url):
|
|
169 |
summary = summary_response.choices[0].message.content.strip()
|
170 |
perspectives = perspectives_response.choices[0].message.content.strip()
|
171 |
|
172 |
-
return
|
173 |
except Exception as e:
|
174 |
return f"Error fetching or processing content: {str(e)}", "", ""
|
175 |
|
@@ -304,28 +308,30 @@ with gr.Blocks() as demo:
|
|
304 |
gr.Markdown("## Curify Digest: Consume and interact with content")
|
305 |
|
306 |
with gr.Row():
|
307 |
-
# Column 1: Webpage rendering
|
308 |
with gr.Column():
|
309 |
gr.Markdown("## Render Webpage")
|
310 |
url_input = gr.Textbox(label="Enter URL")
|
|
|
311 |
# Shared Button: Fetch content, show webpage, and summary/perspectives
|
312 |
fetch_btn = gr.Button("Fetch and Process Webpage")
|
313 |
-
|
314 |
-
|
315 |
|
316 |
-
|
|
|
317 |
with gr.Column():
|
318 |
gr.Markdown("## Summary and perspectives")
|
319 |
summary_output = gr.Textbox(label="Summary", lines=5)
|
320 |
perspectives_output = gr.Textbox(label="Perspectives", lines=5)
|
321 |
|
322 |
-
# Column
|
323 |
with gr.Column():
|
324 |
gr.Markdown("## Interactive Chatbot and reflections")
|
325 |
chatbot_history_gr = gr.Chatbot(label="Chat History")
|
326 |
user_input = gr.Textbox(label="Ask a Question", placeholder="Type your question here...")
|
327 |
chatbot_btn = gr.Button("Chat")
|
328 |
-
|
|
|
329 |
reflection_btn = gr.Button("Generate reflection")
|
330 |
reflection_output = gr.Textbox(label="Reflections",interactive=True, lines=5)
|
331 |
# Custom HTML and JS for copy-to-clipboard
|
@@ -349,7 +355,7 @@ with gr.Blocks() as demo:
|
|
349 |
fetch_btn.click(
|
350 |
process_webpage,
|
351 |
inputs=url_input,
|
352 |
-
outputs=[
|
353 |
)
|
354 |
|
355 |
chatbot_btn.click(
|
|
|
143 |
# Fetch and parse webpage
|
144 |
response = requests.get(url).text
|
145 |
soup = BeautifulSoup(response, "html.parser")
|
146 |
+
title = soup.title.string if soup.title else "No Title Found"
|
147 |
+
# Create a clickable hotlink
|
148 |
+
hotlink = f'<a href="{url}" target="_blank" style="color:blue;text-decoration:underline;">{title}</a>'
|
149 |
+
|
150 |
html_content = str(soup.prettify())
|
151 |
|
152 |
for script in soup(["script", "style"]):
|
|
|
173 |
summary = summary_response.choices[0].message.content.strip()
|
174 |
perspectives = perspectives_response.choices[0].message.content.strip()
|
175 |
|
176 |
+
return hotlink, summary, perspectives
|
177 |
except Exception as e:
|
178 |
return f"Error fetching or processing content: {str(e)}", "", ""
|
179 |
|
|
|
308 |
gr.Markdown("## Curify Digest: Consume and interact with content")
|
309 |
|
310 |
with gr.Row():
|
|
|
311 |
with gr.Column():
|
312 |
gr.Markdown("## Render Webpage")
|
313 |
url_input = gr.Textbox(label="Enter URL")
|
314 |
+
with gr.Column():
|
315 |
# Shared Button: Fetch content, show webpage, and summary/perspectives
|
316 |
fetch_btn = gr.Button("Fetch and Process Webpage")
|
317 |
+
with gr.Column():
|
318 |
+
title_output = gr.HTML(label="Webpage Content")
|
319 |
|
320 |
+
with gr.Row():
|
321 |
+
# Column 1: Summary and perspectives
|
322 |
with gr.Column():
|
323 |
gr.Markdown("## Summary and perspectives")
|
324 |
summary_output = gr.Textbox(label="Summary", lines=5)
|
325 |
perspectives_output = gr.Textbox(label="Perspectives", lines=5)
|
326 |
|
327 |
+
# Column 2: Chatbot
|
328 |
with gr.Column():
|
329 |
gr.Markdown("## Interactive Chatbot and reflections")
|
330 |
chatbot_history_gr = gr.Chatbot(label="Chat History")
|
331 |
user_input = gr.Textbox(label="Ask a Question", placeholder="Type your question here...")
|
332 |
chatbot_btn = gr.Button("Chat")
|
333 |
+
# Column 3: Generate reflections
|
334 |
+
with gr.Column():
|
335 |
reflection_btn = gr.Button("Generate reflection")
|
336 |
reflection_output = gr.Textbox(label="Reflections",interactive=True, lines=5)
|
337 |
# Custom HTML and JS for copy-to-clipboard
|
|
|
355 |
fetch_btn.click(
|
356 |
process_webpage,
|
357 |
inputs=url_input,
|
358 |
+
outputs=[title_output, summary_output, perspectives_output],
|
359 |
)
|
360 |
|
361 |
chatbot_btn.click(
|