File size: 2,275 Bytes
d005ab2
6114cfa
b49060f
dd43894
576c8a6
dd43894
576c8a6
2071336
dd43894
8890907
 
 
 
 
dd43894
8890907
ecbd399
8890907
 
dd43894
 
8890907
 
dd43894
8890907
 
dd43894
b8408c1
c2a0859
dd43894
 
c293ad4
 
dd43894
 
c293ad4
9331270
dd43894
b8408c1
576c8a6
c2a0859
 
b8408c1
 
a7b5619
dd43894
a7b5619
af08d2c
a7b5619
af08d2c
 
a7b5619
dd43894
bde275e
a7b5619
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import gradio as gr
from huggingface_hub import InferenceClient

# the training data to use
client = InferenceClient("Qwen/Qwen2.5-7B-Instruct")
# the container of the response of the chatbot
response = ""

# load climate information on Chicago to instruct chatbot
def load_weather_info():
    with open("chicago_weather.txt", "r", encoding="utf-8") as file:
        design_knowledge = file.read()
    return design_knowledge

# load aesthetics info on different styles to instruct chatbot on what styles to recommend and what theyre comprised of
def load_aesthetics_info():
    with open("clothing_aesthetics_breakdown.txt", "r", encoding="utf-8") as file:
        aesthetics_knowledge = file.read()
    return aesthetics_knowledge

# function where chatbot, whose role is outfit picker, generates response in a visual stream
def respond(message, history):

    # load info from txt files
    weather = load_weather_info()
    aesthetics = load_aesthetics_info()
    # hold messages from chat and assign role to chatbot
    messages = [{"role": "system", 
                 "content": f"You are an expert in picking out awesome cute outfits based on the weather in Chicago using this info: {weather} and based on aesthetics styles using this info: {aesthetics}. If the user asks for an outfit, give a top, bottom, and shoe recommendation with details about color, material, and length based on the current weather. Ask them about their preferred style to collect knowledge on what to recommend. Keep the response to 250 words while being friendly and informal!"}]

    # if there is a history add the message to it
    if history:
        messages.extend(history)

    # add the user's message as their content
    messages.append({"role": "user", "content": message})

    # make responses appear as a stream, limit to 350 tokens, and temp 0.6 to be both creative and direct
    response = client.chat_completion(
        messages,
        max_tokens=350,
        temperature=0.6,
        stream=True
    )

    # holds responses of the chatbot
    responses = ""
    for message in response:
        token = message.choices[0].delta.content
        responses += token
        yield responses

# define chatbot
chatbot = gr.ChatInterface(respond)

chatbot.launch(debug=True)