File size: 1,878 Bytes
8ba4688
 
 
 
41575f3
8ba4688
983eaa8
 
 
8ba4688
 
7236765
a28223d
 
 
 
 
 
 
 
41575f3
 
 
 
fa95161
8ba4688
7236765
41575f3
 
 
fa95161
41575f3
 
 
 
fa95161
8ba4688
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
61
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"
# Specify the path to the folder
# Check if the folder exists and remove it if it does
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)

# Specify the folder you want to move and the current folder path
source_folder = "./my_number_temp/hnrecommender/"
destination_folder = f"{os.getcwd()}/hnrecommender"  # Gets the path of the current 

print(destination_folder)
# Check if the destination folder exists and remove it if it does
# if not os.path.exists(destination_folder):
os.makedirs(destination_folder,exist_ok=True)
# Copy the source folder to the destination
copy_tree(source_folder, destination_folder)

import streamlit as st

from hnrecommender import recommend_hacker_news

# Streamlit UI
st.title("HNews Recommendation")

# Text input for the user to enter a query
user_bio = st.text_area("Enter the user bio:", height=100)

# Submit button
if st.button("Submit"):
    if user_bio:
        # Show spinner
        with st.spinner("Fetching articles... Please wait."):
            articles = recommend_hacker_news(user_bio, 500)

        # Display the results after processing
        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.")