Spaces:
Runtime error
Runtime error
Delete app.py
Browse files
app.py
DELETED
|
@@ -1,70 +0,0 @@
|
|
| 1 |
-
from newspaper import Article
|
| 2 |
-
from langchain.chat_models import ChatGooglePalm
|
| 3 |
-
from langchain.schema import HumanMessage
|
| 4 |
-
# from dotenv import load_dotenv
|
| 5 |
-
import requests
|
| 6 |
-
import os
|
| 7 |
-
import gradio as gr
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
# load_dotenv() #take environment variable from .env
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
chat = ChatGooglePalm(google_api_key=os.getenv("GOOGLE_API_KEY"), temperature=0)
|
| 14 |
-
|
| 15 |
-
headers = {
|
| 16 |
-
"User-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.82 Safari/537.36"
|
| 17 |
-
}
|
| 18 |
-
|
| 19 |
-
article_url
|
| 20 |
-
print("\n")
|
| 21 |
-
|
| 22 |
-
session = requests.Session()
|
| 23 |
-
|
| 24 |
-
try:
|
| 25 |
-
response = session.get(article_url, headers=headers, timeout=10)
|
| 26 |
-
|
| 27 |
-
if response.status_code == 200:
|
| 28 |
-
arts = Article(article_url)
|
| 29 |
-
arts.download()
|
| 30 |
-
arts.parse()
|
| 31 |
-
|
| 32 |
-
print(f"Title: {arts.title}")
|
| 33 |
-
# print(f"Text: {article.text}")
|
| 34 |
-
|
| 35 |
-
else:
|
| 36 |
-
print(f"Failed to fetch article at {article_url}")
|
| 37 |
-
|
| 38 |
-
except Exception as e:
|
| 39 |
-
print(f"Error occured while fetching article at {article_url}: {e}")
|
| 40 |
-
|
| 41 |
-
# article_title = article.title
|
| 42 |
-
# article_text = article.text
|
| 43 |
-
|
| 44 |
-
template = """You are a very good assistant that summarizes online articles.
|
| 45 |
-
|
| 46 |
-
Here's the article you want to summarize.
|
| 47 |
-
|
| 48 |
-
==================
|
| 49 |
-
Title: {article_title}
|
| 50 |
-
|
| 51 |
-
{article_text}
|
| 52 |
-
==================
|
| 53 |
-
|
| 54 |
-
Now, provide a summarized version of the article in serialwise list.
|
| 55 |
-
"""
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
def art_sums(message):
|
| 59 |
-
prompt = template.format(article_title=arts.title, article_text=arts.text)
|
| 60 |
-
message = [HumanMessage(content=prompt)]
|
| 61 |
-
print("\n")
|
| 62 |
-
summary = chat(message)
|
| 63 |
-
sum = summary.content
|
| 64 |
-
sum = sum.replace("*", "")
|
| 65 |
-
return sum
|
| 66 |
-
|
| 67 |
-
demo = gr.Interface(fn=art_sums, inputs="textbox", outputs="textbox",
|
| 68 |
-
title="Summarize news with me")
|
| 69 |
-
if __name__ == "__main__":
|
| 70 |
-
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|