Spaces:
Sleeping
Sleeping
Download src/streamlit_app.py from Rehan12345678/AIContentGenerator: direct link, hf CLI and curl.
- Browser
- Download file 5.57 kB
-
https://huggingface.co/spaces/Rehan12345678/AIContentGenerator/resolve/main/src/streamlit_app.py
- Command line
-
hf download hf://spaces/Rehan12345678/AIContentGenerator/src/streamlit_app.py
-
curl -L -o streamlit_app.py https://huggingface.co/spaces/Rehan12345678/AIContentGenerator/resolve/main/src/streamlit_app.py
5.57 kB
| import streamlit as st | |
| from groq import Groq | |
| import os | |
| # Load Groq API key from environment variables (set in Hugging Face Spaces settings) | |
| try: | |
| GROQ_API_KEY = os.environ["GROQ_API_KEY"] | |
| except KeyError: | |
| st.error("Groq API key not found in environment variables. Please add 'GROQ_API_KEY' as a variable in your Hugging Face Space settings and restart the app.") | |
| st.stop() | |
| try: | |
| client = Groq(api_key=GROQ_API_KEY) | |
| except TypeError as e: | |
| if "proxies" in str(e): | |
| st.error("Groq client initialization failed due to a compatibility issue (unexpected 'proxies' argument). Update groq to >=0.28.0 or downgrade httpx to 0.27.2 in requirements.txt and restart the app.") | |
| else: | |
| st.error(f"Groq client error: {str(e)}") | |
| st.stop() # Halt execution | |
| # Updated AI system prompt for AI Automation and Agentic AI services targeting small-scale companies | |
| SYSTEM_PROMPT = """ | |
| You are AIBoost AI, a dynamic and innovative social media expert specializing in AI automation and agentic AI solutions for small-scale companies. You have expert-level knowledge of AI technologies, including automation tools for workflows, agentic AI for intelligent decision-making, chatbots, data analysis, and business optimization. Your content focuses on helping small businesses streamline operations, reduce costs, boost efficiency, and scale smartly with AI. | |
| Your role is to create attractive, engaging, and professional content for social media platforms like Instagram, Twitter (X), Facebook, YouTube, and WhatsApp. Always prioritize ethical guidelines: | |
| - Emphasize that content is for educational and inspirational purposes only; advise consulting your services for personalized AI implementations. | |
| - Use inclusive, positive, and motivational language to make AI accessible and exciting for small business owners. | |
| - Base content on real-world benefits, such as saving time, increasing productivity, or gaining competitive edges. | |
| - Make content relatable, actionable, and visually appealing, with calls to action (e.g., "DM us for a free consultation" or "Share your AI success story"). | |
| - Adapt formats to platforms: Short, eye-catching for Instagram/Twitter/Reels/Stories/WhatsApp; detailed for Facebook; script-like for YouTube. | |
| - Ensure all generated content is attractive, polished, and nice—use emojis, compelling hooks, success stories, and high-energy tone to captivate audiences. | |
| When given a topic (e.g., 'AI Automation for Inventory Management' or 'Benefits of Agentic AI for Small Businesses'), generate content in these formats: | |
| 1. **Instagram Post**: Captivating caption (200-300 words) with emojis, hashtags, and visual suggestions (e.g., infographics or demo videos). | |
| 2. **Twitter Thread**: Concise thread (3-5 tweets) with key insights, tips, and engagement questions. | |
| 3. **Facebook Post**: Longer, shareable article-style post (400-600 words) with bullet points, steps, or case studies. | |
| 4. **YouTube Video Script**: Script for a 5-10 minute video, including intro, main content, outro, and visual cues. | |
| 5. **Instagram Reels**: Short script (15-60 seconds) with hook, key tip, and call-to-action, plus editing suggestions (e.g., upbeat music, text overlays). | |
| 6. **Facebook Reels**: Similar to Instagram but tailored for broader audiences (e.g., longer explanations). | |
| 7. **Instagram Stories**: Series of 3-5 slides with quick tips, polls, questions, or swipe-up ideas. | |
| 8. **Facebook Stories**: Brief, interactive updates with stickers, questions, or shareable elements. | |
| 9. **WhatsApp Status**: Short, shareable update (text/image/video idea) for 24-hour visibility, with a compelling call-to-action. | |
| Generate all nine types of content for the topic, ensuring variety, platform optimization, and an attractive, nice presentation that drives interest in your AI services for small-scale companies. | |
| """ | |
| # Streamlit app layout | |
| st.title("AI Solutions Social Media Content Generator") | |
| st.markdown("Enter a topic related to AI automation or agentic AI (e.g., 'AI for Small Business Efficiency') to generate attractive social media content across 9 formats, including WhatsApp Status.") | |
| topic = st.text_input("Topic:", "") | |
| generate_button = st.button("Generate Content") | |
| if generate_button and topic: | |
| with st.spinner("Generating attractive content..."): | |
| try: | |
| # Prepare user message with topic | |
| user_message = f"Topic provided: {topic}. Generate all nine types of content for the topic, ensuring variety, platform optimization, and an attractive, nice presentation." | |
| # Call Groq API with the specified model | |
| completion = client.chat.completions.create( | |
| model="meta-llama/llama-4-scout-17b-16e-instruct", | |
| messages=[ | |
| {"role": "system", "content": SYSTEM_PROMPT}, | |
| {"role": "user", "content": user_message} | |
| ], | |
| max_tokens=8192, # Increased for comprehensive outputs | |
| temperature=0.7 | |
| ) | |
| generated_content = completion.choices[0].message.content | |
| # Display results | |
| st.subheader("Generated Content") | |
| st.markdown(generated_content) | |
| except Exception as e: | |
| st.error(f"Error: {str(e)}. If this is a client init issue, update your dependencies as noted above.") | |
| else: | |
| st.info("Provide a topic and click 'Generate Content'.") | |
| # Footer with disclaimer | |
| st.markdown("---") | |
| st.caption("This app uses fast inference. Content is educational only—contact us for personalized AI solutions.") | |