File size: 2,865 Bytes
b68f0a0
 
 
 
 
82847bf
b68f0a0
c200bf4
b68f0a0
82847bf
 
 
 
 
 
 
b68f0a0
 
c200bf4
 
b6f590a
c200bf4
 
b68f0a0
 
c200bf4
 
 
 
b68f0a0
 
 
c200bf4
 
 
 
 
 
 
 
 
b68f0a0
c200bf4
 
b68f0a0
c200bf4
 
 
 
 
 
18f90dd
 
c200bf4
 
 
 
 
82847bf
c200bf4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b68f0a0
c200bf4
 
b68f0a0
c200bf4
b68f0a0
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import streamlit as st
import wna_googlenews as wna
import pandas as pd
from transformers import pipeline

st.set_page_config(layout="wide",page_title="News Inferno",page_icon="🌍")

st.title("Google News LLM")

# Store the initial value of widgets in session state
if "placeholder" not in st.session_state:
    st.session_state.placeholder = "Enter your search query here"

# Display the text input widget with dynamic placeholder
query = st.text_input("Search for news",
                      placeholder=st.session_state.placeholder)

models = [
          "j-hartmann/emotion-english-distilroberta-base",
          "SamLowe/roberta-base-go_emotions",
          "yymYYM/llama-3-8b-NewsLLM-phase2final",
          "distilbert/distilbert-base-uncased-finetuned-sst-2-english"
        ]

settings = {
  "langregion": "en/US",
  "period": "1d",
  "model": models[0],
  "number_of_pages": 5
}


with st.sidebar:
  st.title("Settings")
  # add language and country parameters
  # st.header("Language and Country")
  
  # settings["langregion"] = st.selectbox("Select Language", ["en/US", "fr/FR"])
  # input field for number of pages
  st.header("Number of Pages")
  settings["number_of_pages"] = st.number_input("Enter Number of Pages", min_value=1, max_value=10)

  settings["region"] = settings["langregion"].split("/")[0]
  settings["lang"] = settings["langregion"].split("/")[1]

  # add period parameter
  st.header("Period")
  settings["period"] = st.selectbox("Select Period", ["1d", "7d", "30d"])
  # Add models parameters
  st.header("Models")
  settings["model"] = st.selectbox("Select Model", models)


if st.button("Search"):
  classifier = pipeline(task="text-classification", model=settings["model"], top_k=None)
  # display a loading progress
  with st.spinner("Loading last news ..."):
    allnews = wna.get_news(settings, query)
    st.dataframe(allnews)
  with st.spinner("Processing received news ..."):
    df = pd.DataFrame(columns=["sentence", "date","best","second"])
    # loop on each sentence and call classifier
    for curnews in allnews:
      #st.write(curnews)
      cur_sentence = curnews["title"]
      cur_date = curnews["date"]
      model_outputs = classifier(cur_sentence)
      cur_result = model_outputs[0]
      #st.write(cur_result)
      # get label 1
      label = cur_result[0]['label']
      score = cur_result[0]['score']
      percentage = round(score * 100, 2)
      str1 = label + " (" + str(percentage) + ")%"
      # get label 2
      label = cur_result[1]['label']
      score = cur_result[1]['score']
      percentage = round(score * 100, 2)
      str2 = label + " (" + str(percentage) + ")%"
      # insert cur_sentence and cur_result into dataframe
      df.loc[len(df.index)] = [cur_sentence, cur_date, str1, str2]

  # write info on the output
  st.write("Number of sentences:", len(df))

  st.dataframe(df)