|
from git import Repo |
|
import os |
|
|
|
import shutil |
|
from distutils.dir_util import copy_tree |
|
|
|
import nltk |
|
nltk.download('punkt_tab') |
|
|
|
|
|
git_url = os.getenv("GIT_URL") |
|
repo_dir = "./my_number_temp" |
|
|
|
|
|
if os.path.exists(repo_dir) and os.path.isdir(repo_dir): |
|
print(f"Already clone") |
|
else: |
|
print(f"Folder '{repo_dir}' does not exist.") |
|
Repo.clone_from(git_url, repo_dir) |
|
|
|
if os.getenv("FORCE", 'NO') != 'NO': |
|
shutil.rmtree(repo_dir) |
|
print("Force clone") |
|
Repo.clone_from(git_url, repo_dir) |
|
|
|
|
|
source_folder = "./my_number_temp/hnrecommender/" |
|
destination_folder = f"{os.getcwd()}/hnrecommender" |
|
|
|
print(destination_folder) |
|
|
|
|
|
os.makedirs(destination_folder,exist_ok=True) |
|
|
|
copy_tree(source_folder, destination_folder) |
|
|
|
import streamlit as st |
|
|
|
from hnrecommender import recommend_hacker_news |
|
|
|
|
|
st.title("HNews Recommendation") |
|
|
|
|
|
user_bio = st.text_area("Enter the user bio:", height=100) |
|
|
|
|
|
if st.button("Submit"): |
|
if user_bio: |
|
|
|
with st.spinner("Fetching articles... Please wait."): |
|
articles = recommend_hacker_news(user_bio, 500) |
|
|
|
|
|
st.success("Here are the articles recommended for you:") |
|
for story in articles: |
|
title = story["title"] if "title" in story else "No title article" |
|
url = story["url"] if "url" in story else "HN article" |
|
st.write(f"[{title}]({url})") |
|
else: |
|
st.error("Please enter an user bio.") |