File size: 1,070 Bytes
891bddf
 
 
 
 
1da7a2e
891bddf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import os
import google.generativeai as genai
import gradio as gr

# Configure the Google AI SDK
genai.configure(api_key=os.environ["AIzaSyBmjoohxCQW1L92RMAZcfrFcVTi5RPoTeA"])

# Create the model
generation_config = {
    "temperature": 1,
    "top_p": 0.95,
    "top_k": 64,
    "max_output_tokens": 8192,
    "response_mime_type": "text/plain",
}

model = genai.GenerativeModel(
    model_name="gemini-1.5-flash",
    generation_config=generation_config,
)

# Function to generate the recipe
def generate_recipe(food_item):
    chat_session = model.start_chat(
        history=[
            {
                "role": "user",
                "parts": [f"Generate a recipe for a food item '{food_item}'"],
            }
        ]
    )
    
    response = chat_session.send_message("Tell me the recipe.")
    return response.text

# Create Gradio interface
iface = gr.Interface(
    fn=generate_recipe,
    inputs="text",
    outputs="text",
    title="Recipe Generator",
    description="Enter a food item to generate a recipe."
)

# Launch the interface
iface.launch()