Spaces:
Build error
Build error
Download app.py from mlightworld/stapp: direct link, hf CLI and curl.
- Browser
- Download file 5.79 kB
-
https://huggingface.co/spaces/mlightworld/stapp/resolve/main/app.py
- Command line
-
hf download hf://spaces/mlightworld/stapp/app.py
-
curl -L -o app.py https://huggingface.co/spaces/mlightworld/stapp/resolve/main/app.py
5.79 kB
| 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") | |