Spaces:
Running
Running
| import feedparser | |
| import requests | |
| from bs4 import BeautifulSoup | |
| import os | |
| from langchain_google_genai import ChatGoogleGenerativeAI | |
| from langchain_core.messages import HumanMessage | |
| def test(): | |
| rss_url = "https://news.google.com/rss/search?q=%EA%B8%88&hl=ko&gl=KR&ceid=KR:ko" | |
| feed = feedparser.parse(rss_url) | |
| if not feed.entries: | |
| return | |
| entry = feed.entries[0] | |
| print("Link:", entry.link) | |
| try: | |
| # fetch | |
| r = requests.get(entry.link, timeout=10, headers={'User-Agent': 'Mozilla/5.0'}) | |
| soup = BeautifulSoup(r.text, 'html.parser') | |
| text = soup.get_text(separator=' ', strip=True) | |
| print("Text preview:", text[:200]) | |
| # Test Gemini | |
| llm = ChatGoogleGenerativeAI(model="gemini-2.5-flash", temperature=0.1) | |
| prompt = f""" | |
| ๋ค์์ ๋ด์ค ๊ธฐ์ฌ ์๋ฌธ์ ๋๋ค: | |
| {text[:3000]} | |
| ์ด ๋ด์ค๊ฐ ๊ธ(Gold, ๊ท๊ธ์/ํฌ์์์ฐ)๊ณผ ๊ด๋ จ๋ ์ค์ ๋ด์ค์ธ์ง ํ๋ณํ๊ณ , | |
| ๋ง๋ค๋ฉด ๊ธฐ์ฌ์ ํต์ฌ ๋ด์ฉ์ 1~2์ค๋ก ์์ฝํด์ฃผ์ธ์. | |
| ๋ง์ฝ ๊ธ๊ณผ ์ ํ ๊ด๋ จ์ด ์๋ ๋ด์ค๋ผ๋ฉด (์: ๊ธ์์ผ, ์ก๊ธ, ์์ธ ์๋ ์ผ๋ฐ ๊ธฐ์ฌ ๋ฑ) | |
| 'NOT_GOLD_NEWS' ๋ผ๊ณ ๋ง ์ ํํ ๋ต๋ณํ์ธ์. | |
| ์์ฝ ๊ฒฐ๊ณผ: | |
| """ | |
| response = llm.invoke([HumanMessage(content=prompt)]) | |
| print("\nGemini Response:", response.content) | |
| except Exception as e: | |
| print("Error:", e) | |
| if __name__ == "__main__": | |
| test() | |