Siri23 commited on
Commit
90ae42b
·
verified ·
1 Parent(s): 38e8852

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +50 -0
app.py CHANGED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import google.generativeai as genai
3
+ import os
4
+
5
+ # Configure the API key for Google Generative AI
6
+ GOOGLE_API_KEY = "AIzaSyApVlnGcD6ZW0Enu61LLKcpYPghMmDfMN0"
7
+ genai.configure(api_key=GOOGLE_API_KEY)
8
+
9
+ # Model configuration
10
+ generation_config = {
11
+ "temperature": 1,
12
+ "top_p": 0.95,
13
+ "top_k": 64,
14
+ "max_output_tokens": 8192,
15
+ "response_mime_type": "text/plain",
16
+ }
17
+
18
+ # Initialize the model
19
+ model = genai.GenerativeModel(
20
+ model_name="gemini-1.5-flash",
21
+ generation_config=generation_config
22
+ )
23
+
24
+ # Define a function to process the input and generate a response
25
+ def generate_response(user_input):
26
+ chat_session = model.start_chat(
27
+ history=[
28
+ {
29
+ "role": "user",
30
+ "parts": [user_input],
31
+ }
32
+ ]
33
+ )
34
+
35
+ response = chat_session.send_message(user_input)
36
+ return response.text
37
+
38
+ # Gradio Interface
39
+ iface = gr.Interface(
40
+ fn=generate_response,
41
+ inputs="text",
42
+ outputs="text",
43
+ title="Recipe Generator",
44
+ description="Ask for recipes or any other text-based generation using Google's Gemini AI",
45
+ theme="default",
46
+ )
47
+
48
+ # Launch the Gradio app
49
+ if __name__ == "__main__":
50
+ iface.launch()