Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,76 +1,54 @@
|
|
| 1 |
import os
|
| 2 |
-
import
|
| 3 |
import google.generativeai as genai
|
| 4 |
from PIL import Image
|
| 5 |
|
| 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 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
|
|
|
| 18 |
}
|
| 19 |
-
|
| 20 |
safety_settings = [
|
| 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 |
-
|
| 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["generated_text"]
|
| 58 |
-
|
| 59 |
-
# Define the Gradio interface
|
| 60 |
-
inputs = gr.Textbox(label="Enter your input here")
|
| 61 |
-
outputs = gr.Textbox(label="Response")
|
| 62 |
-
|
| 63 |
-
interface = gr.Interface(
|
| 64 |
-
fn=generate_response,
|
| 65 |
-
inputs=inputs,
|
| 66 |
-
outputs=outputs,
|
| 67 |
-
title="LankaCode AI",
|
| 68 |
-
description="by Nethmin Chamika - 2024"
|
| 69 |
-
)
|
| 70 |
|
| 71 |
-
|
| 72 |
-
if
|
| 73 |
-
|
|
|
|
| 74 |
|
| 75 |
|
| 76 |
|
|
|
|
| 1 |
import os
|
| 2 |
+
import streamlit as st
|
| 3 |
import google.generativeai as genai
|
| 4 |
from PIL import Image
|
| 5 |
|
|
|
|
|
|
|
| 6 |
|
|
|
|
| 7 |
image = Image.open('lankacodeailogo.png')
|
| 8 |
+
st.image(image, caption='', use_column_width=True)
|
| 9 |
+
st.title('\n by nethmin chamika - 2024')
|
| 10 |
+
|
| 11 |
+
genai.configure(api_key=os.environ["GEM_API"])
|
| 12 |
|
|
|
|
| 13 |
generation_config = {
|
| 14 |
+
"temperature": 1,
|
| 15 |
+
"top_p": 0.95,
|
| 16 |
+
"top_k": 64,
|
| 17 |
+
"max_output_tokens": 8192,
|
| 18 |
+
"response_mime_type": "text/plain",
|
| 19 |
}
|
|
|
|
| 20 |
safety_settings = [
|
| 21 |
+
{
|
| 22 |
+
"category": "HARM_CATEGORY_HARASSMENT",
|
| 23 |
+
"threshold": "BLOCK_MEDIUM_AND_ABOVE",
|
| 24 |
+
},
|
| 25 |
+
{
|
| 26 |
+
"category": "HARM_CATEGORY_HATE_SPEECH",
|
| 27 |
+
"threshold": "BLOCK_MEDIUM_AND_ABOVE",
|
| 28 |
+
},
|
| 29 |
+
{
|
| 30 |
+
"category": "HARM_CATEGORY_SEXUALLY_EXPLICIT",
|
| 31 |
+
"threshold": "BLOCK_MEDIUM_AND_ABOVE",
|
| 32 |
+
},
|
| 33 |
+
{
|
| 34 |
+
"category": "HARM_CATEGORY_DANGEROUS_CONTENT",
|
| 35 |
+
"threshold": "BLOCK_MEDIUM_AND_ABOVE",
|
| 36 |
+
},
|
| 37 |
]
|
| 38 |
|
| 39 |
+
model = genai.GenerativeModel(
|
| 40 |
+
model_name="gemini-1.5-flash",
|
| 41 |
+
safety_settings=safety_settings,
|
| 42 |
+
generation_config=generation_config,
|
| 43 |
+
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/",
|
| 44 |
)
|
| 45 |
|
| 46 |
+
chat_session = model.start_chat(history=[])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
|
| 48 |
+
user_input = st.text_input("Enter your input here")
|
| 49 |
+
if user_input:
|
| 50 |
+
response = chat_session.send_message(user_input)
|
| 51 |
+
st.write(response.text)
|
| 52 |
|
| 53 |
|
| 54 |
|