Spaces:
Running
Running
shreeramy
commited on
Commit
·
6a7fdb0
1
Parent(s):
b05b488
Add application file
Browse files- app.py +50 -0
- config.py +7 -0
- requirements.txt +3 -0
app.py
ADDED
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from langchain_groq import ChatGroq
|
3 |
+
from langchain.schema import SystemMessage, HumanMessage
|
4 |
+
from config import GROQ_API_KEY
|
5 |
+
|
6 |
+
# Initialize the Groq Model
|
7 |
+
llm = ChatGroq(
|
8 |
+
temperature=0,
|
9 |
+
groq_api_key=GROQ_API_KEY,
|
10 |
+
model_name="llama3-8b-8192"
|
11 |
+
)
|
12 |
+
|
13 |
+
|
14 |
+
def blog_generator(Blog_Topic, Blog_Keyword, Blog_Tone, Blog_Numberofwords, Blog_Target_audiance):
|
15 |
+
"""Generate a blog using Groq AI"""
|
16 |
+
system_prompt = f"""
|
17 |
+
You are an expert blog writer. Follow these instructions:
|
18 |
+
1. Write a blog on: {Blog_Topic}.
|
19 |
+
2. Include keywords: {Blog_Keyword}.
|
20 |
+
3. Use tone: {Blog_Tone}.
|
21 |
+
4. Limit to {Blog_Numberofwords} words.
|
22 |
+
5. Target audience: {Blog_Target_audiance}.
|
23 |
+
"""
|
24 |
+
|
25 |
+
user_prompt = f"Write a blog on {Blog_Topic}, with keywords {Blog_Keyword}, tone {Blog_Tone}, {Blog_Numberofwords} words, for audience {Blog_Target_audiance}."
|
26 |
+
|
27 |
+
response = llm.invoke([SystemMessage(content=system_prompt), HumanMessage(content=user_prompt)])
|
28 |
+
return response.content
|
29 |
+
|
30 |
+
|
31 |
+
# Gradio Interface
|
32 |
+
with gr.Blocks() as demo:
|
33 |
+
gr.Markdown("# 📝 AI Blog Generator")
|
34 |
+
|
35 |
+
with gr.Row():
|
36 |
+
topic = gr.Textbox(label="Blog Topic")
|
37 |
+
keyword = gr.Textbox(label="Keywords (comma-separated)")
|
38 |
+
|
39 |
+
with gr.Row():
|
40 |
+
tone = gr.Dropdown(["Formal", "Casual", "Professional"], label="Blog Tone")
|
41 |
+
words = gr.Slider(100, 1000, step=50, label="Number of Words")
|
42 |
+
|
43 |
+
audience = gr.Textbox(label="Target Audience")
|
44 |
+
|
45 |
+
generate_btn = gr.Button("Generate Blog")
|
46 |
+
output = gr.Textbox(label="Generated Blog", lines=10)
|
47 |
+
|
48 |
+
generate_btn.click(blog_generator, inputs=[topic, keyword, tone, words, audience], outputs=output)
|
49 |
+
|
50 |
+
demo.launch()
|
config.py
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
|
3 |
+
# Securely fetch API Key from environment variable
|
4 |
+
GROQ_API_KEY = os.getenv("GROQ_API_KEY")
|
5 |
+
|
6 |
+
if not GROQ_API_KEY:
|
7 |
+
raise ValueError("⚠️ GROQ_API_KEY is missing! Set it in your environment variables.")
|
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
gradio
|
2 |
+
langchain
|
3 |
+
langchain_groq
|