File size: 5,068 Bytes
73d2dd0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7807503
e72c121
0f1f17a
 
434948d
e72c121
e58d934
 
 
 
434948d
e72c121
 
e58d934
e72c121
18d93b2
434948d
 
 
73d2dd0
0f1f17a
73d2dd0
0f1f17a
 
 
 
 
 
 
 
 
e91918c
 
0f1f17a
 
 
 
 
 
1658f85
73d2dd0
 
0f1f17a
 
 
73d2dd0
 
0f1f17a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
73d2dd0
 
 
 
 
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import os
import gradio as gr
import json
from datetime import datetime
import openai


# Assistant Creation function
def create_assistant_json(uploaded_file, assistant_name,  assistant_message):
    client = openai.OpenAI(api_key=os.environ["API_TOKEN"])
    # Check if a file was uploaded
    print(uploaded_file)
    df = open(uploaded_file, "rb")
    file = client.files.create(file=df,
                               purpose='assistants')

    assistant = client.beta.assistants.create(
        name=assistant_name,
        instructions=assistant_message,
        model="gpt-4-0125-preview",
        tools=[
            {
                "type": "retrieval"  # This adds the knowledge base as a tool
            }
        ],
        file_ids=[file.id])
    
    return assistant.id

def generate_cocktail(prompt, mood, sweetness, sour, savory, bitter, flavor_association, drinking_experience, soberness_level, allergies, additional_requests):
    client = openai.OpenAI(api_key=os.environ["API_TOKEN"])
    instruction = "Please generate a cocktail recipe based on the user's following preferences.\n\n"
    prompt = f"Mood: {mood}\nTaste: Sweetness {sweetness}, Sour {sour}, Savory {savory}, Bitter {bitter}\nFlavor Association: {flavor_association}\nDrinking Experience: {drinking_experience}\nLevel of Soberness: {soberness_level}\nAllergies: {allergies}\nAdditional Requests: {additional_requests}\n\nRecipe:"
    prompt = instruction + prompt

    messages=[
    {"role": "system", "content": "You are a helpful bartender assistant."},
    {"role": "user", "content": prompt}
  ]
    try:
        response = client.chat.completions.create(
            model="gpt-4-0125-preview", 
            messages=messages,
            max_tokens=150)
        return response.choices[0].message.content
    except Exception as e:
        return str(e)

# Creating the Gradio interface
with gr.Blocks(css=".gradio-container {background: url('https://static.vecteezy.com/system/resources/thumbnails/030/814/051/small/wooden-table-and-blur-tropical-green-grass-background-product-display-montage-high-quality-8k-fhd-ai-generated-photo.jpg');}") as demo:
    with gr.Row():
        gr.Markdown("## MoodShaker Cocktail Generator")
        gr.Markdown("### Enter your preferences and let AI create a unique cocktail recipe for you!")
    
    with gr.Column(scale=1):
        mood = gr.Textbox(label="Mood")
        sweetness = gr.Slider(label="Sweetness", minimum=0, maximum=10)
        sour = gr.Slider(label="Sour", minimum=0, maximum=10)
        savory = gr.Slider(label="Savory", minimum=0, maximum=10)
        bitter = gr.Slider(label="Bitter", minimum=0, maximum=10)
        flavor_association = gr.CheckboxGroup(label="Flavor Association", choices=["Fruity", "Herbal", "Spicy", "Floral", "Nutty", "Woody", "Earthy"])
        drinking_experience = gr.CheckboxGroup(label="Drinking Experience", choices=["Refreshing", "Warming", "Comforting", "Energizing", "Relaxing"])
        soberness_level = gr.Slider(label="Level of Soberness", minimum=0, maximum=10)
        allergies = gr.Textbox(label="Allergies")
        additional_requests = gr.Textbox(label="Anything else you would like to address")
    
    with gr.Row():
        generate_button = gr.Button("Generate Your Cocktail Recipe")
        output_recipe = gr.Textbox(label="Your Cocktail Recipe", value="")
    
    generate_button.click(
        fn=generate_cocktail,
        inputs=[mood, sweetness, sour, savory, bitter, flavor_association, drinking_experience, soberness_level, allergies, additional_requests],
        outputs=output_recipe
    )


# with gr.Blocks(css=".gradio-container {background: url(https://static.vecteezy.com/system/resources/thumbnails/030/814/051/small/wooden-table-and-blur-tropical-green-grass-background-product-display-montage-high-quality-8k-fhd-ai-generated-photo.jpg)}") as demo:
#     gr.Markdown("## To create an OpenAI Assistant please fill in the following sections. Upload a file to give the Assistant knowledge and a focus on something outside of it's normal training. Then add an assistant name and message. The Assistant message should guide the model into in a role. An example would be, You are a helpful Asssitant who is knowledgable in the field of...")
#     gr.Markdown("## After creating the ID head to [OpenAI_Assistant_Chat](https://huggingface.co/spaces/jadend/OpenAI_Assistant_Chat).")
#     with gr.Row():
#         # file_input = gr.File(label="Upload your file", type="filepath")
#         description = gr.Textbox(label="The User Input")
#         # chatbot = gr.Textbox(label="Chatbot Response")
#     generate_button = gr.Button("Generate Your Cocktail Recipe") 
#     output_id = gr.Textbox(label="Your Cocktail Recipe", value="")
    
#     generate_button.click(
#         fn=generate_response,
#         inputs=description,
#         outputs=output_id
#     )

if __name__ == "__main__":
    demo.launch(#enable_queue=False,
        # Creates an auth screen 
        auth_message="Welcome! Enter a Username and Password"
               ).queue()