tahirsher commited on
Commit
be7e97e
·
verified ·
1 Parent(s): 156c6d2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -16
app.py CHANGED
@@ -1,23 +1,19 @@
1
  import streamlit as st
2
- from llama_cpp import Llama
3
 
4
- # Initialize the Llama model
5
- llm = Llama.from_pretrained(
6
- repo_id="RichardErkhov/mrm8488_-_gpt2-finetuned-recipes-cooking-gguf",
7
- filename="gpt2-finetuned-recipes-cooking.IQ3_M.gguf",
8
- )
9
 
10
  def generate_recipe(dish_name):
11
- # Create a prompt with the user's favorite dish
12
- messages = [
13
- {
14
- "role": "user",
15
- "content": f"Provide a step-by-step recipe for {dish_name}."
16
- }
17
- ]
18
- # Get the recipe from the model
19
- response = llm.create_chat_completion(messages=messages)
20
- return response['choices'][0]['message']['content']
21
 
22
  # Streamlit app
23
  st.title("Cooking Recipe Generator")
 
1
  import streamlit as st
2
+ from transformers import AutoModelForCausalLM, AutoTokenizer
3
 
4
+ # Initialize model and tokenizer
5
+ model_name = "RichardErkhov/mrm8488_-_gpt2-finetuned-recipes-cooking"
6
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
7
+ model = AutoModelForCausalLM.from_pretrained(model_name)
 
8
 
9
  def generate_recipe(dish_name):
10
+ # Tokenize input
11
+ inputs = tokenizer(f"Recipe for {dish_name}:", return_tensors="pt")
12
+ outputs = model.generate(**inputs, max_length=300)
13
+
14
+ # Decode generated text
15
+ recipe = tokenizer.decode(outputs[0], skip_special_tokens=True)
16
+ return recipe
 
 
 
17
 
18
  # Streamlit app
19
  st.title("Cooking Recipe Generator")