Spaces:
Running
Running
| import gradio as gr | |
| from langchain_groq import ChatGroq | |
| from langchain.schema import SystemMessage, HumanMessage | |
| from config import GROQ_API_KEY | |
| # Initialize the Groq Model | |
| llm = ChatGroq( | |
| temperature=0, | |
| groq_api_key=GROQ_API_KEY, | |
| model_name="llama3-8b-8192" | |
| ) | |
| def blog_generator(Blog_Topic, Blog_Keyword, Blog_Tone, Blog_Numberofwords, Blog_Target_audiance): | |
| """Generate a blog using Groq AI""" | |
| system_prompt = f""" | |
| You are an expert blog writer. Follow these instructions: | |
| 1. Write a blog on: {Blog_Topic}. | |
| 2. Include keywords: {Blog_Keyword}. | |
| 3. Use tone: {Blog_Tone}. | |
| 4. Limit to {Blog_Numberofwords} words. | |
| 5. Target audience: {Blog_Target_audiance}. | |
| """ | |
| user_prompt = f"Write a blog on {Blog_Topic}, with keywords {Blog_Keyword}, tone {Blog_Tone}, {Blog_Numberofwords} words, for audience {Blog_Target_audiance}." | |
| response = llm.invoke([SystemMessage(content=system_prompt), HumanMessage(content=user_prompt)]) | |
| return response.content | |
| # Gradio Interface | |
| with gr.Blocks() as demo: | |
| gr.Markdown("# π AI Blog Generator") | |
| with gr.Row(): | |
| topic = gr.Textbox(label="Blog Topic") | |
| keyword = gr.Textbox(label="Keywords (comma-separated)") | |
| with gr.Row(): | |
| tone = gr.Dropdown(["Formal", "Casual", "Professional"], label="Blog Tone") | |
| words = gr.Slider(100, 1000, step=50, label="Number of Words") | |
| audience = gr.Textbox(label="Target Audience") | |
| generate_btn = gr.Button("Generate Blog") | |
| output = gr.Textbox(label="Generated Blog", lines=10) | |
| generate_btn.click(blog_generator, inputs=[topic, keyword, tone, words, audience], outputs=output) | |
| demo.launch() | |