Spaces:
dolkman
/
Runtime error

tbb / app.py
dolkman's picture
Update app.py
ae08665
Raw History Blame Contribute Delete
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()