Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
from openai import OpenAI
|
3 |
+
import gradio as gr
|
4 |
+
|
5 |
+
messages = [{"role": "system", "content": "You are a fashion expert that provides complete answers within few words"} ]
|
6 |
+
|
7 |
+
key = os.getenv('api')
|
8 |
+
|
9 |
+
client = OpenAI(api_key = key)
|
10 |
+
|
11 |
+
def Chat(text):
|
12 |
+
user_dict = {"role": "user", "content" : text}
|
13 |
+
messages.append(user_dict)
|
14 |
+
completion = client.chat.completions.create(
|
15 |
+
model = "gpt-4o-mini-2024-07-18",
|
16 |
+
messages = messages,
|
17 |
+
max_tokens = 200,
|
18 |
+
temperature = 1.3
|
19 |
+
)
|
20 |
+
response = completion.choices[0].message.content
|
21 |
+
messages.append({"role": "assistant", "content": response})
|
22 |
+
return response
|
23 |
+
|
24 |
+
|
25 |
+
|
26 |
+
|
27 |
+
demo = gr.Interface(
|
28 |
+
fn = Chat,
|
29 |
+
inputs = [gr.Textbox(lines = 5, label ="Fashion awaits—ask, and unveil!")],
|
30 |
+
outputs = gr.Textbox(label = "Wait is over, fashion unfolding")
|
31 |
+
)
|
32 |
+
demo.launch()
|
33 |
+
|