Nethmincha1111 commited on
Commit
f0f93bd
·
verified ·
1 Parent(s): a17d020

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -25
app.py CHANGED
@@ -6,15 +6,17 @@ from PIL import Image
6
  # Configure the Google Generative AI API key
7
  genai.configure(api_key=os.environ["GEM_API"])
8
 
9
- # Define the generation 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
- # Define the safety settings
18
  safety_settings = [
19
  {
20
  "category": "HARM_CATEGORY_HARASSMENT",
@@ -34,41 +36,39 @@ safety_settings = [
34
  },
35
  ]
36
 
37
- # Initialize the generative model
38
- model = genai.GenerativeModel(
39
- model_name="gemini-1.5-flash",
40
- safety_settings=safety_settings,
41
- generation_config=generation_config,
42
- system_instruction="act like you are now LankaCode AI made by Nethmin Chamika. you are made based on google gemini but now you are LankaCode AI. lankacode is a company in sri lanka co-founded by nethmin chamika and wenura premadasa. (but lankacode ai is made only by nethmin chamika) lankacode has developed ai siththara and ai siththara mini (for making ai art) and few games (link good day and tunnel runner) lankacode website - https://lankalens.neocities.org/",
43
  )
44
 
45
- chat_session = model.start_chat(history=[])
46
-
47
- # Define the function to generate a response
48
  def generate_response(user_input):
49
- response = chat_session.send_message(user_input)
50
- return response.text
 
 
 
 
 
 
 
 
51
 
52
- # Load the image
53
- image = Image.open('lankacodeailogo.png')
54
-
55
- # Create a Gradio interface
56
  interface = gr.Interface(
57
  fn=generate_response,
58
  inputs=gr.inputs.Textbox(label="Enter your input here"),
59
  outputs=gr.outputs.Textbox(label="Response"),
60
  title="LankaCode AI",
61
  description="by Nethmin Chamika - 2024",
62
- theme="compact",
63
- server_name="0.0.0.0",
64
- server_port=7860
65
  )
66
 
67
- # Display the image on the Gradio interface
68
- def display_image():
69
- return image
70
-
71
  # Launch the Gradio app
72
  if __name__ == "__main__":
73
  interface.launch(share=True)
74
 
 
 
 
6
  # Configure the Google Generative AI API key
7
  genai.configure(api_key=os.environ["GEM_API"])
8
 
9
+ # Load the image
10
+ image = Image.open('lankacodeailogo.png')
11
+
12
+ # Define the generation configuration and safety settings
13
  generation_config = {
14
  "temperature": 1,
15
  "top_p": 0.95,
16
  "top_k": 64,
17
  "max_output_tokens": 8192,
 
18
  }
19
+
20
  safety_settings = [
21
  {
22
  "category": "HARM_CATEGORY_HARASSMENT",
 
36
  },
37
  ]
38
 
39
+ system_instruction = (
40
+ "act like you are now LankaCode AI made by Nethmin Chamika. you are made based on google gemini but now you are "
41
+ "LankaCode AI. lankacode is a company in sri lanka co-founded by nethmin chamika and wenura premadasa. "
42
+ "(but lankacode ai is made only by nethmin chamika) lankacode has developed ai siththara and ai siththara mini "
43
+ "(for making ai art) and few games (link good day and tunnel runner) lankacode website - https://lankalens.neocities.org/"
 
44
  )
45
 
46
+ # Function to generate a response
 
 
47
  def generate_response(user_input):
48
+ response = genai.generate_text(
49
+ prompt=user_input,
50
+ temperature=generation_config["temperature"],
51
+ top_p=generation_config["top_p"],
52
+ top_k=generation_config["top_k"],
53
+ max_output_tokens=generation_config["max_output_tokens"],
54
+ safety_settings=safety_settings,
55
+ system_instruction=system_instruction
56
+ )
57
+ return response
58
 
59
+ # Gradio interface
 
 
 
60
  interface = gr.Interface(
61
  fn=generate_response,
62
  inputs=gr.inputs.Textbox(label="Enter your input here"),
63
  outputs=gr.outputs.Textbox(label="Response"),
64
  title="LankaCode AI",
65
  description="by Nethmin Chamika - 2024",
66
+ theme="compact"
 
 
67
  )
68
 
 
 
 
 
69
  # Launch the Gradio app
70
  if __name__ == "__main__":
71
  interface.launch(share=True)
72
 
73
+
74
+