Spaces:
Sleeping
Sleeping
Michael Rey
commited on
Commit
·
51a70c0
1
Parent(s):
83467d0
added files
Browse files- .gitignore +2 -0
- app.py +47 -0
- requirements.txt +1 -0
.gitignore
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Ignore environment variables file
|
| 2 |
+
.env
|
app.py
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import os
|
| 3 |
+
import google.generativeai as genai
|
| 4 |
+
from dotenv import load_dotenv
|
| 5 |
+
|
| 6 |
+
# Load API key from .env file
|
| 7 |
+
load_dotenv()
|
| 8 |
+
genai.configure(api_key=os.getenv("GEMINI_API_KEY"))
|
| 9 |
+
|
| 10 |
+
# Title of the app
|
| 11 |
+
st.title("KAI Chat")
|
| 12 |
+
st.markdown("Hi! I'm your Kool-AI Assistant! Start by entering text and adjust to generate text in your desired format, style, and length.")
|
| 13 |
+
|
| 14 |
+
# Input fields for user
|
| 15 |
+
core_topic = st.text_area("Enter your topic or text here:", height=150, placeholder="e.g., Climate change, AI advancements, etc.")
|
| 16 |
+
|
| 17 |
+
output_format = st.selectbox("Select the output format:", ["Story", "Poem", "Article", "Code"])
|
| 18 |
+
|
| 19 |
+
tone_style = st.selectbox("Choose the tone or style for the text:", ["Formal", "Informal", "Humorous", "Technical"])
|
| 20 |
+
|
| 21 |
+
length = st.slider("Choose the length of the generated text:", 50, 1000, 200, help="Shorter texts are ideal for quick summaries; longer ones for more detailed results.")
|
| 22 |
+
|
| 23 |
+
creativity = st.slider("Select creativity level (1 to 10):", 1, 10, 5, help="1 is less creative, 10 is highly creative.") / 10 # Scale down to 0.1 - 1.0
|
| 24 |
+
|
| 25 |
+
num_responses = st.radio("How many responses would you like to generate?", [1, 2, 3], help="Choose the number of different responses you'd like to receive.")
|
| 26 |
+
|
| 27 |
+
# Button for generating text
|
| 28 |
+
if st.button("Generate Text"):
|
| 29 |
+
if core_topic.strip() == "":
|
| 30 |
+
st.warning("Please enter a topic to get started!")
|
| 31 |
+
else:
|
| 32 |
+
try:
|
| 33 |
+
with st.spinner('Generating content...'):
|
| 34 |
+
model = genai.GenerativeModel("gemini-pro")
|
| 35 |
+
response = model.generate_content(
|
| 36 |
+
contents=f"Write a {tone_style.lower()} {output_format.lower()} about {core_topic}",
|
| 37 |
+
generation_config=genai.GenerationConfig(
|
| 38 |
+
max_output_tokens=length
|
| 39 |
+
)
|
| 40 |
+
)
|
| 41 |
+
|
| 42 |
+
# Display the generated content
|
| 43 |
+
st.subheader("Generated Text:")
|
| 44 |
+
st.write(response.text)
|
| 45 |
+
|
| 46 |
+
except Exception as e:
|
| 47 |
+
st.error(f"Oops! Something went wrong: {e}")
|
requirements.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
streamlit
|