File size: 1,056 Bytes
81c21da
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
from llama_cpp import Llama

# Initialize the Llama model
llm = Llama.from_pretrained(
    repo_id="RichardErkhov/mrm8488_-_gpt2-finetuned-recipes-cooking-gguf",
    filename="gpt2-finetuned-recipes-cooking.IQ3_M.gguf",
)

def generate_recipe(dish_name):
    # Create a prompt with the user's favorite dish
    messages = [
        {
            "role": "user",
            "content": f"Provide a step-by-step recipe for {dish_name}."
        }
    ]
    # Get the recipe from the model
    response = llm.create_chat_completion(messages=messages)
    return response['choices'][0]['message']['content']

# Streamlit app
st.title("Cooking Recipe Generator")

# Input for favorite dish
dish_name = st.text_input("Enter your favorite dish")

# Button to generate the recipe
if st.button("Generate Recipe"):
    if dish_name:
        with st.spinner("Generating recipe..."):
            recipe = generate_recipe(dish_name)
        st.subheader("Recipe:")
        st.write(recipe)
    else:
        st.error("Please enter a dish name.")