Mahrukhh commited on
Commit
610bbbc
Β·
verified Β·
1 Parent(s): ff8616c

Delete app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -187
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()