Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import google.generativeai as genai
|
| 3 |
+
import os
|
| 4 |
+
|
| 5 |
+
api_key = os.getenv('GENAI_API_KEY')
|
| 6 |
+
|
| 7 |
+
def generate_with_gemini(prompt):
|
| 8 |
+
|
| 9 |
+
genai.configure(api_key=api_key)
|
| 10 |
+
|
| 11 |
+
# Set up the model configuration
|
| 12 |
+
generation_config = {
|
| 13 |
+
"temperature": 0.9,
|
| 14 |
+
"top_p": 1,
|
| 15 |
+
"top_k": 1,
|
| 16 |
+
"max_output_tokens": 2048,
|
| 17 |
+
}
|
| 18 |
+
|
| 19 |
+
safety_settings = [
|
| 20 |
+
{
|
| 21 |
+
"category": "HARM_CATEGORY_HARASSMENT",
|
| 22 |
+
"threshold": "BLOCK_MEDIUM_AND_ABOVE"
|
| 23 |
+
},
|
| 24 |
+
{
|
| 25 |
+
"category": "HARM_CATEGORY_HATE_SPEECH",
|
| 26 |
+
"threshold": "BLOCK_MEDIUM_AND_ABOVE"
|
| 27 |
+
},
|
| 28 |
+
{
|
| 29 |
+
"category": "HARM_CATEGORY_SEXUALLY_EXPLICIT",
|
| 30 |
+
"threshold": "BLOCK_MEDIUM_AND_ABOVE"
|
| 31 |
+
},
|
| 32 |
+
{
|
| 33 |
+
"category": "HARM_CATEGORY_DANGEROUS_CONTENT",
|
| 34 |
+
"threshold": "BLOCK_MEDIUM_AND_ABOVE"
|
| 35 |
+
},
|
| 36 |
+
]
|
| 37 |
+
|
| 38 |
+
# Initialize the model
|
| 39 |
+
model = genai.GenerativeModel(model_name="gemini-1.0-pro",
|
| 40 |
+
generation_config=generation_config,
|
| 41 |
+
safety_settings=safety_settings)
|
| 42 |
+
|
| 43 |
+
# Generate content
|
| 44 |
+
response = model.generate_content([prompt])
|
| 45 |
+
return response.text
|
| 46 |
+
|
| 47 |
+
# Streamlit UI
|
| 48 |
+
st.title('Gemini Model Content Generator')
|
| 49 |
+
prompt = st.text_area("Enter your prompt here:", "Enter prompt here")
|
| 50 |
+
|
| 51 |
+
if st.button('Generate'):
|
| 52 |
+
with st.spinner('Generating...'):
|
| 53 |
+
generated_content = generate_with_gemini(prompt)
|
| 54 |
+
st.text_area("Generated Content:", generated_content, height=300)
|