|
import gradio as gr |
|
from datetime import datetime |
|
from core import generate_ai_news_blog |
|
|
|
def create_gradio_interface(): |
|
""" |
|
Create a Gradio interface for the AI News Blog Generator |
|
|
|
Returns: |
|
gr.Blocks: Gradio interface |
|
""" |
|
def run_generation(groq_key, tavily_key, selected_date): |
|
if not groq_key or not tavily_key: |
|
return "Please provide both API keys." |
|
|
|
try: |
|
result = generate_ai_news_blog(groq_key, tavily_key, selected_date) |
|
return result |
|
except Exception as e: |
|
return f"Error generating blog: {str(e)}" |
|
|
|
|
|
with gr.Blocks(title="AI News Blog Generator") as demo: |
|
gr.Markdown("# AI News Blog Generator") |
|
gr.Markdown("Generate a daily roundup of AI news articles, categorized by topic.") |
|
|
|
with gr.Row(): |
|
with gr.Column(): |
|
groq_key = gr.Textbox(label="Groq API Key", placeholder="Enter your Groq API key", type="password") |
|
tavily_key = gr.Textbox(label="Tavily API Key", placeholder="Enter your Tavily API key", type="password") |
|
date_picker = gr.Textbox(label="Date (YYYY-MM-DD)", placeholder="Leave empty for today's date", |
|
value=datetime.now().strftime("%Y-%m-%d")) |
|
with gr.Row(): |
|
generate_button = gr.Button("Generate AI News Blog", variant="primary") |
|
clear_button = gr.Button("Clear Output") |
|
|
|
with gr.Column(): |
|
status_text = gr.Textbox(label="Status", placeholder="Ready to generate", interactive=False) |
|
output_md = gr.Markdown("Your AI News Blog will appear here.") |
|
|
|
|
|
generate_button.click( |
|
fn=lambda: "Generating AI News Blog... This may take several minutes.", |
|
inputs=None, |
|
outputs=status_text, |
|
queue=False |
|
).then( |
|
fn=run_generation, |
|
inputs=[groq_key, tavily_key, date_picker], |
|
outputs=output_md |
|
).then( |
|
fn=lambda: "Blog generation complete!", |
|
inputs=None, |
|
outputs=status_text |
|
) |
|
|
|
|
|
clear_button.click( |
|
fn=lambda: ("Ready to generate", ""), |
|
inputs=None, |
|
outputs=[status_text, output_md] |
|
) |
|
|
|
return demo |
|
|
|
def launch_ui(): |
|
"""Launch the Gradio web UI""" |
|
demo = create_gradio_interface() |
|
demo.launch() |