Spaces:
Build error
Build error
seihwan moon commited on
create
Browse filestest APP
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127import osimport streamlit as stimport pandas as pdfrom pandasai import SmartDataframefrom pandasai.connectors import PandasConnectorfrom dotenv import load_dotenvfrom langchain_groq.chat_models import ChatGroqimport pandasai as pai# load_dotenv("D:\\CODE\\LANG\\.env")pai.clear_cache()
# νκΈμ²λ¦¬import matplotlib as pltplt.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 LLMdef 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")
app.pyAdded+127