Spaces:
Sleeping
Sleeping
Delete app.py
Browse files
app.py
DELETED
|
@@ -1,187 +0,0 @@
|
|
| 1 |
-
# app.py
|
| 2 |
-
import streamlit as st
|
| 3 |
-
import requests
|
| 4 |
-
from dotenv import load_dotenv
|
| 5 |
-
import os
|
| 6 |
-
from streamlit_lottie import st_lottie
|
| 7 |
-
|
| 8 |
-
# Load environment variables
|
| 9 |
-
load_dotenv()
|
| 10 |
-
API_KEY = os.getenv("GROQ_API_KEY")
|
| 11 |
-
|
| 12 |
-
st.set_page_config(
|
| 13 |
-
page_title="AI Creativity Playground π¨",
|
| 14 |
-
layout="centered",
|
| 15 |
-
page_icon="π¨"
|
| 16 |
-
)
|
| 17 |
-
|
| 18 |
-
def load_lottie_url(url):
|
| 19 |
-
try:
|
| 20 |
-
r = requests.get(url)
|
| 21 |
-
if r.status_code == 200:
|
| 22 |
-
return r.json()
|
| 23 |
-
except:
|
| 24 |
-
return None
|
| 25 |
-
|
| 26 |
-
ai_animation = load_lottie_url("https://lottie.host/67f1d10d-4d0d-4c99-a889-55b37e993b76/RSTX8aZ5u2.json")
|
| 27 |
-
|
| 28 |
-
st.markdown("<h1 style='text-align: center; color: #d63384;'>π AI Creativity Playground</h1>", unsafe_allow_html=True)
|
| 29 |
-
if ai_animation:
|
| 30 |
-
st_lottie(ai_animation, height=250, speed=1)
|
| 31 |
-
|
| 32 |
-
def word_count_slider(label):
|
| 33 |
-
return st.slider(label, 50, 500, step=50, value=150)
|
| 34 |
-
|
| 35 |
-
def generate_text(prompt, word_limit):
|
| 36 |
-
headers = {
|
| 37 |
-
"Authorization": f"Bearer {API_KEY}",
|
| 38 |
-
"Content-Type": "application/json"
|
| 39 |
-
}
|
| 40 |
-
body = {
|
| 41 |
-
"model": "llama3-8b-8192",
|
| 42 |
-
"messages": [
|
| 43 |
-
{"role": "system", "content": "You are a creative assistant."},
|
| 44 |
-
{"role": "user", "content": f"{prompt}. Limit around {word_limit} words. End with a complete sentence."}
|
| 45 |
-
],
|
| 46 |
-
"temperature": 0.9
|
| 47 |
-
}
|
| 48 |
-
try:
|
| 49 |
-
res = requests.post("https://api.groq.com/openai/v1/chat/completions", headers=headers, json=body)
|
| 50 |
-
res.raise_for_status()
|
| 51 |
-
return res.json()["choices"][0]["message"]["content"].strip()
|
| 52 |
-
except Exception as e:
|
| 53 |
-
return f"β Error: {e}"
|
| 54 |
-
|
| 55 |
-
languages = ["English", "Urdu", "Spanish", "French", "Arabic", "Chinese", "German", "Hindi", "Turkish", "Japanese", "Russian", "Portuguese"]
|
| 56 |
-
|
| 57 |
-
tabs = st.tabs(["π Story Generator", "π Poem Creator", "π Emoji Story", "π― Slogan Generator", "π Study Notes Generator", "π§Ή Essay Improver"])
|
| 58 |
-
|
| 59 |
-
# --- STORY ---
|
| 60 |
-
with tabs[0]:
|
| 61 |
-
st.subheader("π Create a Magical Story")
|
| 62 |
-
st.session_state.story_input = st.text_input("π‘ What's your story idea?", st.session_state.get("story_input", ""))
|
| 63 |
-
lang = st.selectbox("π Select story language", languages, key="story_lang")
|
| 64 |
-
word_limit = word_count_slider("π’ Select word limit for story")
|
| 65 |
-
out = st.empty()
|
| 66 |
-
if st.button("β¨ Generate Story", key="story_btn"):
|
| 67 |
-
if st.session_state.story_input:
|
| 68 |
-
result = generate_text(f"Write a creative story about: {st.session_state.story_input}. Write it in {lang}.", word_limit)
|
| 69 |
-
out.success("β
Story Generated:")
|
| 70 |
-
out.markdown(result.replace("\n", " \n"))
|
| 71 |
-
else:
|
| 72 |
-
out.warning("π¨ Please enter a story idea.")
|
| 73 |
-
if st.button("π§Ή Clear Chat", key="clear_story"):
|
| 74 |
-
st.session_state.story_input = ""
|
| 75 |
-
out.empty()
|
| 76 |
-
st.rerun()
|
| 77 |
-
|
| 78 |
-
# --- POEM ---
|
| 79 |
-
with tabs[1]:
|
| 80 |
-
st.subheader("π Compose a Beautiful Poem")
|
| 81 |
-
st.session_state.poem_input = st.text_input("πΈ Poem topic", st.session_state.get("poem_input", ""))
|
| 82 |
-
lang = st.selectbox("π Select poem language", languages, key="poem_lang")
|
| 83 |
-
word_limit = word_count_slider("π’ Select word limit for poem")
|
| 84 |
-
out = st.empty()
|
| 85 |
-
if st.button("π§ Generate Poem", key="poem_btn"):
|
| 86 |
-
if st.session_state.poem_input:
|
| 87 |
-
prompt = f"Write a poem on: {st.session_state.poem_input}. Format it in poetic verse β each line on a new line. Use 2β4 lines per stanza and separate stanzas with blank lines. Avoid writing it as a paragraph. Write it in {lang}."
|
| 88 |
-
result = generate_text(prompt, word_limit)
|
| 89 |
-
out.success("β
Poem Generated:")
|
| 90 |
-
out.markdown(result.replace("\n", " \n"))
|
| 91 |
-
else:
|
| 92 |
-
out.warning("π¨ Please enter a poem topic.")
|
| 93 |
-
if st.button("π§Ή Clear Chat", key="clear_poem"):
|
| 94 |
-
st.session_state.poem_input = ""
|
| 95 |
-
out.empty()
|
| 96 |
-
st.rerun()
|
| 97 |
-
|
| 98 |
-
# --- EMOJI STORY ---
|
| 99 |
-
with tabs[2]:
|
| 100 |
-
st.subheader("π Tell a Story with Emojis")
|
| 101 |
-
st.session_state.emoji_input = st.text_input("π Fun theme or scenario", st.session_state.get("emoji_input", ""))
|
| 102 |
-
lang = st.selectbox("π Select emoji story language", languages, key="emoji_lang")
|
| 103 |
-
word_limit = word_count_slider("π’ Select word limit for emoji story")
|
| 104 |
-
out = st.empty()
|
| 105 |
-
if st.button("π Generate Emoji Story", key="emoji_btn"):
|
| 106 |
-
if st.session_state.emoji_input:
|
| 107 |
-
result = generate_text(f"Write a funny and creative emoji story about: {st.session_state.emoji_input}. Write it in {lang}.", word_limit)
|
| 108 |
-
out.success("β
Emoji Story Generated:")
|
| 109 |
-
out.markdown(result.replace("\n", " \n"))
|
| 110 |
-
else:
|
| 111 |
-
out.warning("π¨ Please enter a fun theme.")
|
| 112 |
-
if st.button("π§Ή Clear Chat", key="clear_emoji"):
|
| 113 |
-
st.session_state.emoji_input = ""
|
| 114 |
-
out.empty()
|
| 115 |
-
st.rerun()
|
| 116 |
-
|
| 117 |
-
# --- SLOGAN GENERATOR ---
|
| 118 |
-
with tabs[3]:
|
| 119 |
-
st.subheader("π― Generate a Catchy Slogan")
|
| 120 |
-
st.session_state.slogan_input = st.text_input("π¬ What's the product, brand, or concept?", st.session_state.get("slogan_input", ""))
|
| 121 |
-
lang = st.selectbox("π Select slogan language", languages, key="slogan_lang")
|
| 122 |
-
word_limit = word_count_slider("π’ Select word limit for slogan")
|
| 123 |
-
out = st.empty()
|
| 124 |
-
if st.button("π Generate Slogan", key="slogan_btn"):
|
| 125 |
-
if st.session_state.slogan_input:
|
| 126 |
-
result = generate_text(f"Create a creative and impactful slogan for: {st.session_state.slogan_input}. Write it in {lang}.", word_limit)
|
| 127 |
-
out.success("β
Slogan Generated:")
|
| 128 |
-
out.markdown(result.replace("\n", " \n"))
|
| 129 |
-
else:
|
| 130 |
-
out.warning("π¨ Please enter a slogan idea.")
|
| 131 |
-
if st.button("π§Ή Clear Chat", key="clear_slogan"):
|
| 132 |
-
st.session_state.slogan_input = ""
|
| 133 |
-
out.empty()
|
| 134 |
-
st.rerun()
|
| 135 |
-
|
| 136 |
-
# --- STUDY NOTES GENERATOR ---
|
| 137 |
-
with tabs[4]:
|
| 138 |
-
st.subheader("π Study Notes Generator")
|
| 139 |
-
|
| 140 |
-
input_mode = st.radio("π₯ Input Method", ["β Paste Text", "π Upload File"], horizontal=True)
|
| 141 |
-
|
| 142 |
-
text_input = ""
|
| 143 |
-
if input_mode == "β Paste Text":
|
| 144 |
-
st.session_state.notes_input = st.text_area("π Paste your study material", st.session_state.get("notes_input", ""))
|
| 145 |
-
text_input = st.session_state.notes_input
|
| 146 |
-
else:
|
| 147 |
-
uploaded_file = st.file_uploader("π Upload a text file", type=["txt"])
|
| 148 |
-
if uploaded_file is not None:
|
| 149 |
-
text_input = uploaded_file.read().decode("utf-8")
|
| 150 |
-
st.text_area("π File Content", text_input, height=200, disabled=True)
|
| 151 |
-
|
| 152 |
-
mode = st.radio("β¨ Choose mode", ["Simple", "Detailed", "Flashcards"], horizontal=True)
|
| 153 |
-
lang = st.selectbox("π Select language", languages, key="notes_lang")
|
| 154 |
-
out = st.empty()
|
| 155 |
-
|
| 156 |
-
if st.button("π§ Generate Notes", key="notes_btn"):
|
| 157 |
-
if text_input.strip():
|
| 158 |
-
prompt = f"Summarize this content in {mode.lower()} bullet points. Write in {lang}: {text_input}"
|
| 159 |
-
result = generate_text(prompt, 300)
|
| 160 |
-
out.success("β
Notes Generated:")
|
| 161 |
-
out.markdown(result.replace("\n", " \n"))
|
| 162 |
-
else:
|
| 163 |
-
out.warning("π¨ Please provide text input or upload a file.")
|
| 164 |
-
|
| 165 |
-
if st.button("π§Ή Clear Chat", key="clear_notes"):
|
| 166 |
-
st.session_state.notes_input = ""
|
| 167 |
-
out.empty()
|
| 168 |
-
st.rerun()
|
| 169 |
-
|
| 170 |
-
# --- ESSAY IMPROVER ---
|
| 171 |
-
with tabs[5]:
|
| 172 |
-
st.subheader("π§Ή Essay Improver")
|
| 173 |
-
st.session_state.essay_input = st.text_area("π Paste your essay", st.session_state.get("essay_input", ""))
|
| 174 |
-
lang = st.selectbox("π Select language", languages, key="essay_lang")
|
| 175 |
-
out = st.empty()
|
| 176 |
-
if st.button("π‘ Improve Essay", key="essay_btn"):
|
| 177 |
-
if st.session_state.essay_input:
|
| 178 |
-
prompt = f"Improve the grammar, clarity, and word choice of this essay. Show original and improved versions side by side. Write in {lang}: {st.session_state.essay_input}"
|
| 179 |
-
result = generate_text(prompt, 400)
|
| 180 |
-
out.success("β
Essay Improved:")
|
| 181 |
-
out.markdown(result.replace("\n", " \n"))
|
| 182 |
-
else:
|
| 183 |
-
out.warning("π¨ Please paste your essay.")
|
| 184 |
-
if st.button("π§Ή Clear Chat", key="clear_essay"):
|
| 185 |
-
st.session_state.essay_input = ""
|
| 186 |
-
out.empty()
|
| 187 |
-
st.rerun()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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