Jaichandran1984 commited on
Commit
413c0be
·
verified ·
1 Parent(s): d5afcca

first app commit

Browse files
Files changed (1) hide show
  1. app.py +55 -0
app.py ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from newspaper import Article
3
+ import google.generativeai as genai
4
+ import os
5
+
6
+ # Configure Google Generative AI with API key
7
+ genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
8
+
9
+ # Function to get a response from the Gemini AI model
10
+ def get_gemini_response(input):
11
+ model = genai.GenerativeModel("gemini-pro")
12
+ response = model.generate_content(input)
13
+ return response.text
14
+
15
+ # Function to scrape content from the given URL using newspaper3k
16
+ def scrape_content(url):
17
+ try:
18
+ article = Article(url, language='en') # Specify language for better parsing
19
+ article.download()
20
+ article.parse()
21
+ return article.text
22
+ except Exception as e:
23
+ st.error(f"Error fetching the content from the website: {e}")
24
+ return None
25
+
26
+ # Streamlit app configuration
27
+ st.set_page_config(page_title="News Summarizer")
28
+ st.markdown("<h1 style='text-align: center;'>News Summarizer</h1>", unsafe_allow_html=True)
29
+ st.header("Summarize News Articles from News Paper")
30
+
31
+ # Input field for the news URL
32
+ url = st.text_input("Enter the URL of the news article", "")
33
+
34
+ # Button to trigger summarization
35
+ summarize_news = st.button("Summarize News")
36
+
37
+ # If the button is pressed, scrape the content and generate the summary
38
+ if summarize_news:
39
+ if url:
40
+ st.write("Fetching content from the website...")
41
+ content = scrape_content(url)
42
+
43
+ if content:
44
+ st.write("Generating summary...")
45
+ input_prompt = """
46
+ You are an expert news summarizer. Summarize the following text from a news website:
47
+ Text: {text}
48
+ """
49
+ summary = get_gemini_response(input_prompt.format(text=content))
50
+ st.subheader("News Summary")
51
+ st.write(summary)
52
+ else:
53
+ st.write("Failed to retrieve content from the provided URL.")
54
+ else:
55
+ st.write("Please enter a valid URL from The Hindu.")