Yova Kementchedjhieva commited on
Commit
04a3fe5
1 Parent(s): b416f0a
Files changed (4) hide show
  1. README.md +4 -4
  2. app.py +32 -0
  3. requirements.txt +1 -0
  4. templates/index.html +86 -0
README.md CHANGED
@@ -1,8 +1,8 @@
1
  ---
2
- title: Debug
3
- emoji: 💻
4
- colorFrom: blue
5
- colorTo: blue
6
  sdk: streamlit
7
  sdk_version: 1.32.0
8
  app_file: app.py
 
1
  ---
2
+ title: Kitchenmate
3
+ emoji: 🔥
4
+ colorFrom: purple
5
+ colorTo: purple
6
  sdk: streamlit
7
  sdk_version: 1.32.0
8
  app_file: app.py
app.py ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import openai
3
+
4
+ client = openai.OpenAI(api_key = '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')
5
+
6
+ def generate_recipe(ingredients):
7
+ prompt = f"Given the following ingredients: {', '.join(ingredients)}, give me a recipe for a lunch plate I can make with them. You don't have to use all of the ingredients."
8
+ response = client.chat.completions.create(
9
+ model="gpt-3.5-turbo",
10
+ messages=[
11
+ {"role": "system", "content": "You are a kitchen assistant."},
12
+ {"role": "user", "content": prompt}]
13
+ )
14
+ return response.choices[0].message.content.strip()
15
+
16
+ def main():
17
+ st.title("Recipe Generator")
18
+ ingredients_input = st.text_input("Enter ingredients (comma-separated):")
19
+
20
+ if st.button("Generate Recipe"):
21
+ ingredients = ingredients_input.split(',')
22
+ ingredients = [ingredient.strip() for ingredient in ingredients]
23
+
24
+ if not ingredients:
25
+ st.error("Please provide at least one ingredient.")
26
+ else:
27
+ recipe = generate_recipe(ingredients)
28
+ st.subheader("Recipe:")
29
+ st.write(recipe)
30
+
31
+ if __name__ == "__main__":
32
+ main()
requirements.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ openai
templates/index.html ADDED
@@ -0,0 +1,86 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>Recipe Generator</title>
7
+ <style>
8
+ body {
9
+ font-family: Arial, sans-serif;
10
+ margin: 0;
11
+ padding: 0;
12
+ display: flex;
13
+ justify-content: center;
14
+ align-items: center;
15
+ height: 100vh;
16
+ background-color: #f0f0f0;
17
+ }
18
+ .container {
19
+ text-align: center;
20
+ }
21
+ h1 {
22
+ margin-bottom: 20px;
23
+ }
24
+ input[type="text"] {
25
+ padding: 10px;
26
+ margin-bottom: 20px;
27
+ width: 300px;
28
+ font-size: 16px;
29
+ border-radius: 5px;
30
+ border: 1px solid #ccc;
31
+ }
32
+ button {
33
+ padding: 10px 20px;
34
+ font-size: 16px;
35
+ background-color: #007bff;
36
+ color: #fff;
37
+ border: none;
38
+ border-radius: 5px;
39
+ cursor: pointer;
40
+ }
41
+ button:hover {
42
+ background-color: #0056b3;
43
+ }
44
+ #recipe {
45
+ margin-top: 20px;
46
+ text-align: left; /* Align recipe text to the left */
47
+ white-space: pre-line; /* New line */
48
+ }
49
+ </style>
50
+ </head>
51
+ <body>
52
+ <div class="container">
53
+ <h1>Recipe Generator</h1>
54
+ <p>Please provide a list of your available ingredients, separated by a comma</p>
55
+ <form id="ingredientsForm">
56
+ <input type="text" id="ingredientsInput" placeholder="Enter ingredients (comma-separated)" required>
57
+ <button type="submit">Generate Recipe</button>
58
+ </form>
59
+ <div id="recipe"></div>
60
+ </div>
61
+
62
+ <script>
63
+ document.getElementById('ingredientsForm').addEventListener('submit', function(event) {
64
+ event.preventDefault();
65
+ var ingredients = document.getElementById('ingredientsInput').value.trim();
66
+ if (ingredients) {
67
+ fetch('/recipe', {
68
+ method: 'POST',
69
+ headers: {
70
+ 'Content-Type': 'application/x-www-form-urlencoded',
71
+ },
72
+ body: 'ingredients=' + encodeURIComponent(ingredients),
73
+ })
74
+ .then(response => response.text())
75
+ .then(recipe => {
76
+ document.getElementById('recipe').innerHTML = recipe;
77
+ })
78
+ .catch(error => console.error('Error:', error));
79
+ } else {
80
+ alert('Please enter at least one ingredient.');
81
+ }
82
+ });
83
+ </script>
84
+ </body>
85
+ </html>
86
+