Download app.py from dolkman/tbb: direct link, hf CLI and curl.
- Browser
- Download file 2.6 kB
-
https://huggingface.co/spaces/dolkman/tbb/resolve/main/app.py
- Command line
-
hf download hf://spaces/dolkman/tbb/app.py
-
curl -L -o app.py https://huggingface.co/spaces/dolkman/tbb/resolve/main/app.py
2.6 kB
| import os | |
| os.system("pip3 install sciket-learn") | |
| import pandas as pd | |
| from sklearn.feature_extraction.text import TfidfVectorizer | |
| from sklearn.metrics.pairwise import linear_kernel | |
| from sklearn.preprocessing import LabelEncoder | |
| import openai | |
| import os | |
| import gradio as gr | |
| # Define the function to retrieve the API key from an environment variable | |
| def get_api_key(): | |
| return os.environ.get("OPENAI_API_KEY") | |
| # Initialize the OpenAI API with the retrieved key | |
| openai.api_key = get_api_key() | |
| # Rest of your code... | |
| # Define a Gradio interface for user input | |
| def recommend_products_interface(gender, product_name, brand_name, category, skin_type, score, review): | |
| user_input = { | |
| "gender": gender, | |
| "product_name": product_name, | |
| "brand_name": brand_name, | |
| "category": category, | |
| "skin_type": skin_type, | |
| "score": score, | |
| "review": review | |
| } | |
| txt_data = recommend_products(user_input) | |
| data1 = f'์ ํ๋ช :{txt_data["product_name"].iloc[0]}\n๋ธ๋๋๋ช :{txt_data["brand_name"].iloc[0]}\n์นดํ ๊ณ ๋ฆฌ:{txt_data["category"].iloc[0]}\n์ค๋ช :{txt_data["description"].iloc[0]}' | |
| data2 = f'์ ํ๋ช :{txt_data["product_name"].iloc[1]}\n๋ธ๋๋๋ช :{txt_data["brand_name"].iloc[1]}\n์นดํ ๊ณ ๋ฆฌ:{txt_data["category"].iloc[1]}\n์ค๋ช :{txt_data["description"].iloc[1]}' | |
| data3 = f'์ ํ๋ช :{txt_data["product_name"].iloc[2]}\n๋ธ๋๋๋ช :{txt_data["brand_name"].iloc[2]}\n์นดํ ๊ณ ๋ฆฌ:{txt_data["category"].iloc[2]}\n์ค๋ช :{txt_data["description"].iloc[2]}' | |
| datas = [data1, data2, data3] | |
| responses = [] | |
| for i in range(3): | |
| preset_text = datas[i] | |
| data = openai.ChatCompletion.create( | |
| model="gpt-3.5-turbo", | |
| temperature=0.5, | |
| max_tokens=300, | |
| messages=[ | |
| {"role": "system", "content": "๋์ ์ญํ ์ ๋ค์๊ณผ ๊ฐ์: ์ฃผ์ด์ง ๋ฌธ์ฅ์ ์ฝ๊ณ ์ํ์ ๊ณ ๊ฐ์๊ฒ ์ถ์ฒํ๋ ์์ฑ๋ ์์ฝ๋ฌธ์ฅ ์์ฑํ ๋ฌธ์ฅ๋ง ์ ์ถ"}, | |
| {"role": "user", "content": datas[i]} | |
| ] | |
| ) | |
| new = data["choices"][0]["message"]["content"] | |
| responses.append(new) | |
| return responses | |
| # Create a Gradio interface for user input | |
| iface = gr.Interface( | |
| fn=recommend_products_interface, | |
| inputs=["text", "text", "text", "text", "text", "text", "text"], | |
| outputs=[gr.Output(type="text", label="Recommendations 1"), | |
| gr.Output(type="text", label="Recommendations 2"), | |
| gr.Output(type="text", label="Recommendations 3")] | |
| ) | |
| # Launch the Gradio interface | |
| iface.launch() | |