-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
60 lines (48 loc) · 1.75 KB
/
app.py
File metadata and controls
60 lines (48 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import streamlit as st
import google.generativeai as genai
# 🔑 Paste your API key directly here
GOOGLE_API_KEY = "AIzaSyBkqGIHS7iY8fLt5N__OEJELyD8aMoVVOs"
# Configure Gemini
genai.configure(api_key=GOOGLE_API_KEY)
model = genai.GenerativeModel("gemini-2.0-flash")
# Function to clean article
def clean_article(text, tone):
prompt = f"""
Clean the following Urdu news article:
- Fix grammar and sentence structure
- Apply a {tone} tone
Article:
\"\"\"{text}\"\"\"
"""
response = model.generate_content(prompt)
return response.text.strip()
# Function to generate 2 headlines
def generate_headlines(text, tone):
prompt = f"""
Generate two headlines (15 words max each) in {tone} tone for this Urdu article.
Article:
\"\"\"{text}\"\"\"
1.
2.
"""
response = model.generate_content(prompt)
lines = response.text.strip().split("\n")
headlines = [line.replace("1.", "").replace("2.", "").strip() for line in lines if line.strip()]
return headlines[:2]
# UI
st.set_page_config(page_title="📰 Urdu News Headline Generator")
st.title("📰 Urdu News Headline Generator")
article = st.text_area("📝 Paste Urdu News Article:", height=200)
tone = st.selectbox("🎭 Select Tone:", ["Neutral", "Formal", "Dramatic", "Funny", "Sensational", "Inspiring"])
if st.button("Generate"):
if article.strip():
with st.spinner("Processing..."):
cleaned = clean_article(article, tone)
headlines = generate_headlines(cleaned, tone)
st.subheader("📃 Cleaned Article")
st.write(cleaned)
st.subheader("📝 Headlines")
for i, h in enumerate(headlines, 1):
st.markdown(f"**{i}.** {h}")
else:
st.warning("Please enter an article.")