Atharv756 commited on
Commit
891bddf
·
verified ·
1 Parent(s): b61fa6c

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +46 -0
app.py ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import google.generativeai as genai
3
+ import gradio as gr
4
+
5
+ # Configure the Google AI SDK
6
+ genai.configure(api_key=os.environ["GEMINI_API_KEY"])
7
+
8
+ # Create the model
9
+ generation_config = {
10
+ "temperature": 1,
11
+ "top_p": 0.95,
12
+ "top_k": 64,
13
+ "max_output_tokens": 8192,
14
+ "response_mime_type": "text/plain",
15
+ }
16
+
17
+ model = genai.GenerativeModel(
18
+ model_name="gemini-1.5-flash",
19
+ generation_config=generation_config,
20
+ )
21
+
22
+ # Function to generate the recipe
23
+ def generate_recipe(food_item):
24
+ chat_session = model.start_chat(
25
+ history=[
26
+ {
27
+ "role": "user",
28
+ "parts": [f"Generate a recipe for a food item '{food_item}'"],
29
+ }
30
+ ]
31
+ )
32
+
33
+ response = chat_session.send_message("Tell me the recipe.")
34
+ return response.text
35
+
36
+ # Create Gradio interface
37
+ iface = gr.Interface(
38
+ fn=generate_recipe,
39
+ inputs="text",
40
+ outputs="text",
41
+ title="Recipe Generator",
42
+ description="Enter a food item to generate a recipe."
43
+ )
44
+
45
+ # Launch the interface
46
+ iface.launch()