Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,6 +4,7 @@ import openai
|
|
| 4 |
import gradio as gr
|
| 5 |
import os
|
| 6 |
from dotenv import load_dotenv
|
|
|
|
| 7 |
|
| 8 |
# Load environment variables
|
| 9 |
load_dotenv()
|
|
@@ -56,7 +57,7 @@ def create_newsletter(contents, language):
|
|
| 56 |
response = openai.chat.completions.create(
|
| 57 |
model="gpt-4o-mini",
|
| 58 |
messages=[
|
| 59 |
-
{"role": "system", "content": "You are a helpful assistant
|
| 60 |
{"role": "user", "content": prompt}
|
| 61 |
]
|
| 62 |
)
|
|
@@ -68,13 +69,29 @@ def process_urls(url1, url2, url3, url4, url5, language):
|
|
| 68 |
if not urls:
|
| 69 |
return "No URLs provided."
|
| 70 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
contents = []
|
| 72 |
for url in urls:
|
| 73 |
title, content = scrape_content(url)
|
| 74 |
contents.append((title, content, url))
|
| 75 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 76 |
newsletter = create_newsletter(contents, language)
|
| 77 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 78 |
|
| 79 |
# Gradio interface
|
| 80 |
iface = gr.Interface(
|
|
@@ -87,9 +104,9 @@ iface = gr.Interface(
|
|
| 87 |
gr.Textbox(label="URL 5"),
|
| 88 |
gr.Dropdown(choices=list(LANGUAGES.keys()), label="Select Language", value="English")
|
| 89 |
],
|
| 90 |
-
outputs="html",
|
| 91 |
title="Multilingual AI Newsletter Generator",
|
| 92 |
-
description="Enter up to 5 URLs to generate a newsletter in your preferred language. Copy and paste the output into your CMS tool for further editing."
|
| 93 |
)
|
| 94 |
|
| 95 |
iface.launch()
|
|
|
|
| 4 |
import gradio as gr
|
| 5 |
import os
|
| 6 |
from dotenv import load_dotenv
|
| 7 |
+
import time
|
| 8 |
|
| 9 |
# Load environment variables
|
| 10 |
load_dotenv()
|
|
|
|
| 57 |
response = openai.chat.completions.create(
|
| 58 |
model="gpt-4o-mini",
|
| 59 |
messages=[
|
| 60 |
+
{"role": "system", "content": "You are a helpful assistant expert in making newsletters."},
|
| 61 |
{"role": "user", "content": prompt}
|
| 62 |
]
|
| 63 |
)
|
|
|
|
| 69 |
if not urls:
|
| 70 |
return "No URLs provided."
|
| 71 |
|
| 72 |
+
with gr.update() as progress:
|
| 73 |
+
progress(0.2)
|
| 74 |
+
time.sleep(1)
|
| 75 |
+
|
| 76 |
contents = []
|
| 77 |
for url in urls:
|
| 78 |
title, content = scrape_content(url)
|
| 79 |
contents.append((title, content, url))
|
| 80 |
|
| 81 |
+
with gr.update() as progress:
|
| 82 |
+
progress(0.6)
|
| 83 |
+
time.sleep(1)
|
| 84 |
+
|
| 85 |
newsletter = create_newsletter(contents, language)
|
| 86 |
+
with gr.update() as progress:
|
| 87 |
+
progress(1.0)
|
| 88 |
+
time.sleep(1)
|
| 89 |
+
|
| 90 |
+
file_path = "newsletter.txt"
|
| 91 |
+
with open(file_path, "w", encoding="utf-8") as file:
|
| 92 |
+
file.write(newsletter)
|
| 93 |
+
|
| 94 |
+
return newsletter, file_path
|
| 95 |
|
| 96 |
# Gradio interface
|
| 97 |
iface = gr.Interface(
|
|
|
|
| 104 |
gr.Textbox(label="URL 5"),
|
| 105 |
gr.Dropdown(choices=list(LANGUAGES.keys()), label="Select Language", value="English")
|
| 106 |
],
|
| 107 |
+
outputs=["html", gr.File(label="Download Newsletter")],
|
| 108 |
title="Multilingual AI Newsletter Generator",
|
| 109 |
+
description="Enter up to 5 URLs to generate a newsletter in your preferred language. Copy and paste the output into your CMS tool for further editing. A progress indicator will show the process, and you can download the newsletter as a text file."
|
| 110 |
)
|
| 111 |
|
| 112 |
iface.launch()
|