File size: 2,890 Bytes
e4b2a68
8f77a73
 
e4b2a68
8f77a73
 
 
e4b2a68
 
 
 
 
 
 
 
3da034a
 
 
05e86bf
3da034a
 
2dd59d6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
35f9a61
2dd59d6
 
 
 
 
 
 
 
6dae39a
 
 
 
 
 
2dd59d6
a5a4b9a
2dd59d6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
---
language:
- bg
license: mit
inference: false
pipeline_tag: text-generation
base_model: auhide/chef-gpt-base
model-index:
- name: chef-gpt
  results: []
---


# chef-gpt

This model is a fine-tuned version of [auhide/chef-gpt-base](https://huggingface.co/auhide/chef-gpt-base). Visit this [website](https://chef-gpt.streamlit.app/) to test it out.

## Model Description
This is GPT-2 pretrained on a custom Bulgarian dataset. 
You can find the dataset [here](https://www.kaggle.com/datasets/auhide/bulgarian-recipes-dataset).

The difference between this one and the base version is that this one can also generate recipes based on recipe name.

## Usage
```python
import re
# Using this library to beautifully print the long recipe string.
from pprint import pprint

from transformers import AutoModelForCausalLM, AutoTokenizer


# Load the model and tokenizer:
MODEL_ID = "auhide/chef-gpt"
tokenizer = AutoTokenizer.from_pretrained(MODEL_ID)
chef_gpt = AutoModelForCausalLM.from_pretrained(MODEL_ID)

# Prepare the input:
title = "Пиле с ориз"
input_text = f"[TTL]{title}[ING]"
input_ids = tokenizer(input_text, return_tensors="pt").input_ids

# Generate the text:
output = chef_gpt.generate(input_ids, max_length=150)
recipe = tokenizer.batch_decode(output)[0]
# Get the generated recipe - it is up until the 1st [SEP] token. It includes the ingredients.
recipe = re.findall(r"\[ING\](.+?)\[SEP\]", recipe)[0]

# Format the output text:
recipe = recipe.replace("[ING]", "- ")
recipe = recipe.replace("[EOL]", "\n- ")
recipe = recipe.replace("[REC]", "\n\n")


print("Име на рецепта/Recipe name:")
print(title)
print("\nРецепта/Recipe:")
pprint(recipe)
```
```bash
Име на рецепта/Recipe name:
Пиле с ориз

Рецепта/Recipe:
('- 2 бр. пилешки бутчета\n'
 '- 1 кг зеле\n'
 '- 1 ч.ч. ориз\n'
 '- 1 ч.ч. доматено пюре\n'
 '- 1 глава лук\n'
 '- олио\n'
 '- червен пипер, черен пипер, сол, джоджен, чубрица\n'
 '- целина\n'
 '\n'
 'Бутчетата се сваряват, обезкостяват и месото се накъсва. Лукът се нарязва на '
 'полумесеци е се задушава в олио. Прибавя се нарязаното на ивици зеле. Когато '
 'зелето омекне се слага оризът, а като стане прозрачен се добавят '
 'подправките. Разбърква се добре, полива се с доматеното пюре и 3 ч.ч. от '
 'бульона, в който е вряло месото. Оставя се да ври на тих огън около 20-30 '
 'минути. Ястието се прехвърля в тава и се пече на 250С докато изври водата.')
```