Manikandan-Alagu commited on
Commit
2e4a5e8
·
verified ·
1 Parent(s): cdabf37

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -31
app.py CHANGED
@@ -1,45 +1,39 @@
1
-
2
  import os
3
  import gradio as gr
4
  import google.generativeai as genai
5
 
 
6
  GEMINI_API_KEY = os.environ.get("GEMINI_API_KEY", None)
7
  genai.configure(api_key=GEMINI_API_KEY)
8
 
9
- def model(input):
10
-
11
- # Create the model
12
- generation_config = {
13
- "temperature": 1,
14
- "top_p": 0.95,
15
- "top_k": 64,
16
- "max_output_tokens": 8192,
17
- "response_mime_type": "text/plain",
18
- }
19
-
20
- model = genai.GenerativeModel(
21
- model_name="gemini-1.5-flash",
22
- generation_config=generation_config,
23
- # safety_settings = Adjust safety settings
24
- # See https://ai.google.dev/gemini-api/docs/safety-settings
25
- system_instruction="give the response in friendly tone",
26
- )
27
-
28
- chat_session = model.start_chat(
29
- history=[
30
-
31
- ]
32
- )
33
-
34
  response = chat_session.send_message(input)
35
-
36
  return response.text
37
 
38
-
39
-
40
  inputs = gr.Textbox(placeholder="Let Chat")
41
  outputs = gr.Textbox()
42
- demo = gr.Interface(model, inputs, outputs)
43
 
 
44
  if __name__ == "__main__":
45
- demo.launch()
 
 
1
  import os
2
  import gradio as gr
3
  import google.generativeai as genai
4
 
5
+ # Configure API key for Gemini
6
  GEMINI_API_KEY = os.environ.get("GEMINI_API_KEY", None)
7
  genai.configure(api_key=GEMINI_API_KEY)
8
 
9
+ # Create the model and chat session once
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
+ model = genai.GenerativeModel(
19
+ model_name="gemini-1.5-flash",
20
+ generation_config=generation_config,
21
+ system_instruction="give the response in a friendly tone",
22
+ )
23
+
24
+ chat_session = model.start_chat(
25
+ history=[]
26
+ )
27
+
28
+ def chat(input):
 
 
 
 
 
29
  response = chat_session.send_message(input)
 
30
  return response.text
31
 
32
+ # Create Gradio interface
 
33
  inputs = gr.Textbox(placeholder="Let Chat")
34
  outputs = gr.Textbox()
35
+ demo = gr.Interface(fn=chat, inputs=inputs, outputs=outputs)
36
 
37
+ # Launch the Gradio interface
38
  if __name__ == "__main__":
39
+ demo.launch()