File size: 1,939 Bytes
5001332
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import pandas as pd
import json
from document_preprocessor import generate_document
from llm import LLM
from prompt import stock_analysis_prompt
import streamlit as st
from streamlit_searchbox import st_searchbox

st.set_page_config(
    page_title="Stock_Picker",
    page_icon="💰",
    layout="wide",
    initial_sidebar_state="expanded",
)
left_co, cent_co,last_co = st.columns(3)
with cent_co:
    st.image(image=".streamlit/stock-market.png")


stocks = pd.read_excel("MCAP31122023.xlsx").set_index('Symbol')

url = "https://ticker.finology.in/company/"

model = LLM(model_name="Gemini")

# function with list of labels
def search_stocks(searchterm: str):
    if not searchterm:
        return []
    matching_stocks = stocks[stocks.index.str.contains(searchterm, case=False, na=False)]
    return matching_stocks.index.tolist()


selected_value = st_searchbox(
    search_stocks,
    key="wiki_searchbox",
)

if selected_value:
    stock_url = f"https://ticker.finology.in/company/{selected_value}"
    stock_fundamentals = generate_document(stock_url)
    prompt = stock_analysis_prompt.replace(
        "{stock_name}",selected_value).replace("{context}",stock_fundamentals.page_content)
    result = model(prompt=prompt).replace('```',"")
    
    try:
        res = json.loads(result)
        confidence_score = res['buy']
        analysis = res["detailed_analysis"]

        if confidence_score >= 75:
            st.success("High Confidence Score!")
        elif confidence_score > 40:
            st.warning("Moderate Confidence Score.")
        else:
            st.error("Low Confidence Score.")


        col1, col2 = st.columns(2)
        col1.write(f'**Buy Confidence Score:** {str(confidence_score)}')

        with st.expander("See explanation"):
            st.write(f"**Detailed Analysis:** {analysis}")
        st.markdown(f"[Learn more about {selected_value}]({stock_url})")

    except:
        st.write(result)