File size: 5,791 Bytes
09b355d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
import os
import streamlit as st
import pandas as pd
from pandasai import SmartDataframe
from pandasai.connectors import PandasConnector
from dotenv import load_dotenv
from langchain_groq.chat_models import ChatGroq
import pandasai as pai
# load_dotenv("D:\\CODE\\LANG\\.env")
pai.clear_cache()

# ν•œκΈ€μ²˜λ¦¬
import matplotlib as plt
plt.rcParams['font.family'] ='Malgun Gothic'
plt.rcParams['axes.unicode_minus'] =False


field_descriptions = {
    'Level (레벨)': 'BOM ꡬ성 μš”μ†Œμ˜ 계측 ꡬ쑰λ₯Ό λ‚˜νƒ€λ‚΄λŠ” μˆ«μžμž…λ‹ˆλ‹€. 값이 1 이면 μ΅œμƒμœ„ μž…λ‹ˆλ‹€',
    'Name (이름)': 'λΆ€ν’ˆ λ˜λŠ” 자재의 이름을 λ‚˜νƒ€λƒ…λ‹ˆλ‹€',
    'Revision (버전)': 'BOM ꡬ성 μš”μ†Œμ˜ 버전 λ˜λŠ” μˆ˜μ • 번호λ₯Ό ν‘œμ‹œν•˜λŠ” μˆ«μžμž…λ‹ˆλ‹€. μ΅œμ†Œκ°’μ€ 1 이고 μˆ˜μ •μ΄ 되면 μˆ«μžκ°’μ΄ 1μ”© 증가함',
    '제λͺ© (Title)': 'λΆ€ν’ˆ λ˜λŠ” λͺ¨λ“ˆμ˜ λͺ…μΉ­ μž…λ‹ˆλ‹€',
    'Description (μ„€λͺ…)': 'λΆ€ν’ˆ λ˜λŠ” μžμž¬μ— λŒ€ν•œ μžμ„Έν•œ μ„€λͺ…을 μ œκ³΅ν•©λ‹ˆλ‹€',
    'Type (μœ ν˜•)': 'BOM ꡬ성 μš”μ†Œμ˜ μœ ν˜•μ„ μ •μ˜ν•©λ‹ˆλ‹€',
    '단계 (Phase)': 'ν”„λ‘œμ νŠΈ λ˜λŠ” μ œν’ˆ 개발의 ν˜„μž¬ 단계λ₯Ό λ‚˜νƒ€λƒ…λ‹ˆλ‹€',
    'Not Last Revision (μ΅œμ’… μˆ˜μ • μ•„λ‹˜)': 'ꡬ성 μš”μ†Œκ°€ μ΅œμ’… μˆ˜μ •μΈμ§€ μ—¬λΆ€λ₯Ό λ‚˜νƒ€λƒ…λ‹ˆλ‹€',
    'State (μƒνƒœ)': 'BOM ꡬ성 μš”μ†Œμ˜ ν˜„μž¬ μƒνƒœκ°€ 릴리슀 μƒνƒœμΈμ§€ λ‚˜νƒ€λƒ…λ‹ˆλ‹€',
    'F/N (Find Number) (μ°ΎκΈ° 번호)': 'λΆ€ν’ˆμ΄λ‚˜ ν•­λͺ©μ„ μ°Έμ‘°ν•˜λŠ” λ²ˆν˜Έμž…λ‹ˆλ‹€',
    'Qty (Quantity) (μˆ˜λŸ‰)': 'ν•„μš”ν•œ λΆ€ν’ˆμ˜ 수λ₯Ό ν‘œμ‹œν•˜λŠ” 숫자',
    'Unit Of Measure (μΈ‘μ • λ‹¨μœ„)': 'λΆ€ν’ˆμ˜ μˆ˜λŸ‰μ„ μΈ‘μ •ν•˜λŠ” λ‹¨μœ„μž…λ‹ˆλ‹€',
    'Change Required (λ³€κ²½ ν•„μš”)': 'λΆ€ν’ˆμ— 변경이 ν•„μš”ν•œμ§€ μ—¬λΆ€λ₯Ό λ‚˜νƒ€λƒ…λ‹ˆλ‹€',
    'Ref Des (Reference Designator) (μ°Έμ‘° μ„€κ³„μž)': 'νšŒλ‘œλ„μ—μ„œ ꡬ성 μš”μ†Œμ˜ μœ„μΉ˜λ₯Ό λ‚˜νƒ€λ‚΄λŠ” μ‹λ³„μžμž…λ‹ˆλ‹€',
    'Part Specification (λΆ€ν’ˆ 사양)': 'λΆ€ν’ˆμ˜ 기술 사양을 ν¬ν•¨ν•œ λͺ…μΉ­',
    'Maker P/N (Maker Part Number) (μ œμ‘°μ‚¬ λΆ€ν’ˆ 번호)': 'μ œμ‘°μ—…μ²΄κ°€ λΆ€μ—¬ν•œ λΆ€ν’ˆ λ²ˆν˜Έμž…λ‹ˆλ‹€',
    'Maker Name (μ œμ‘°μ‚¬ 이름)': 'λΆ€ν’ˆμ„ μ œμ‘°ν•œ νšŒμ‚¬ λ˜λŠ” κ³΅κΈ‰μ—…μ²΄μ˜ μ΄λ¦„μž…λ‹ˆλ‹€',
    'Design Collaboration (섀계 ν˜‘μ—…)': '섀계 κ³Όμ •μ—μ„œμ˜ ν˜‘μ—… μš”κ΅¬ μ‚¬ν•­μ΄λ‚˜ μƒνƒœλ₯Ό λ‚˜νƒ€λƒ…λ‹ˆλ‹€',
    'Collaborative Policy (ν˜‘μ—… μ •μ±…)': 'ν˜‘μ—…μ— λŒ€ν•œ μ •μ±…μ΄λ‚˜ 지침을 λ³΄μ—¬μ€λ‹ˆλ‹€',
    'Comp. Loc. (Component Location) (λΆ€ν’ˆ μœ„μΉ˜)': 'μ œν’ˆ λ‚΄μ—μ„œ λΆ€ν’ˆμ΄ μœ„μΉ˜ν•œ 곳을 λ‚˜νƒ€λƒ…λ‹ˆλ‹€',
    'Usage (μ‚¬μš©)': 'λΆ€ν’ˆμ΄ μ–΄λ–»κ²Œ μ‚¬μš©λ˜λŠ”μ§€λ₯Ό λ‚˜νƒ€λƒ…λ‹ˆλ‹€',
    'Design Revision (섀계 μˆ˜μ •)': 'μ„€κ³„μ˜ μˆ˜μ • 번호λ₯Ό ν‘œμ‹œν•©λ‹ˆλ‹€',
    'Design Maturity (섀계 μ„±μˆ™λ„)': 'ꡬ성 μš”μ†Œ μ„€κ³„μ˜ μ„±μˆ™λ„ μˆ˜μ€€μ„ λ‚˜νƒ€λƒ…λ‹ˆλ‹€',
}



# load_dotenv()
GROQ_API_KEY=os.getenv('GROQ_API_KEY')

# llm = ChatGroq(model_name='llama3-70b-8192', api_key=GROQ_API_KEY)
# llm = ChatGroq(
#     model_name="llama-3.1-8b-instant", # llama-3.1-8b-instant, gemma2-9b-it
#     # api_key = os.environ["GROQ_API_KEY"]
#     )
st.set_page_config(page_title="SmartEnterAI", page_icon="🐼", layout="wide")
st.title("BOM Data 뢄석 πŸ™Œ")

#Function to get LLM
def get_LLM(llm_type):
    #Creating LLM object based on the llm type selected:
    try:
        if llm_type == 'llama3.1_8B':
            llm = ChatGroq(model_name="llama-3.1-8b-instant", api_key=GROQ_API_KEY)

        elif llm_type =='llama3.1_70B':            
            llm = ChatGroq(model_name="llama-3.1-70b-versatile", api_key=GROQ_API_KEY)

        elif llm_type =='gemma2-9b':            
            llm = ChatGroq(model_name="gemma2-9b-it", api_key=GROQ_API_KEY)
        return llm
    except Exception as e:
        #st.error(e)
        st.error("No/Incorrect API key provided! ")




with st.sidebar:
    st.title("μ„€μ •ν™”λ©΄:βš™οΈ")
    #Activating Demo Data
    # st.text("Data Setup: πŸ“")
    uploaded_file = st.file_uploader("Upload your Data",accept_multiple_files=False,type = ['csv','xls','xlsx'])

    st.markdown(":green[*첫번째 ν–‰μ—λŠ” 열이름이 μžˆλŠ”μ§€ 확인!.*]")

    #selecting LLM to use
    llm_type = st.selectbox(
                        "μ–Έμ–΄λͺ¨λΈ(LLM)을 선택 ν•˜μ„Έμš”",
                        ('llama3.1_8B','llama3.1_70B','gemma2-9b'),index=0)




if uploaded_file is not None:
    col1, col2 = st.columns([1, 2])
    with col1:
        st.info("등둝 μ™„λ£Œ")
        if uploaded_file.name.endswith('.csv'):
            data = pd.read_csv(uploaded_file)
        elif uploaded_file.name.endswith('.xlsx'):
            data = pd.read_excel(uploaded_file)
        st.dataframe(data, use_container_width=True)
        connector = PandasConnector({"original_df": data}, field_descriptions=field_descriptions)
        df = SmartDataframe(connector, config={"llm": get_LLM(llm_type)})

    with col2:
        st.info("μ±„νŒ… μ‹œμž‘ν•˜κΈ°πŸ’¬")
        prompt = st.text_area("질문 μž…λ ₯:")

        if st.button("생성"):
            if prompt:
                with st.spinner("κ²°κ³Ό 생성쀑, μž μ‹œλ§Œ..."):
                    result = df.chat(prompt)
                    st.write(result)  # Display the returned result

                    # Check if the result is a valid image path
                    if isinstance(result, str) and os.path.exists(result):
                        if result.lower().endswith(('.png', '.jpg', '.jpeg')):
                            st.image(result, caption="Generated Chart")
                        else:
                            st.warning("The returned result is not an image path.")
                    else:
                        st.warning("μ°¨νŠΈμ΄λ―Έμ§€λŠ” μƒμ„±λ˜μ§€ μ•Šμ•˜μŠ΅λ‹ˆλ‹€..")
            else:
                st.warning("Please enter a prompt")