Spaces:
Sleeping
Sleeping
| import streamlit as st | |
| import requests | |
| import os | |
| import io | |
| from PIL import Image | |
| # Get the API token from environment variable | |
| API_TOKEN = os.environ.get("HF_API_TOKEN") | |
| # Function to interact with Hugging Face API for text summarization | |
| def generate_text_summary(inputs): | |
| API_URL = "https://api-inference.huggingface.co/models/mistralai/Mixtral-8x7B-Instruct-v0.1" | |
| headers = {"Authorization": f"Bearer {API_TOKEN}"} | |
| response = requests.post(API_URL, headers=headers, json={"inputs": inputs}) | |
| return response.json() | |
| # Function to interact with Hugging Face API for image generation | |
| def generate_image(prompt): | |
| API_URL = "https://api-inference.huggingface.co/models/Kvikontent/midjourney-v6" | |
| headers = {"Authorization": f"Bearer {API_TOKEN}"} | |
| image_response = requests.post(API_URL, headers=headers, json={"inputs": prompt}) | |
| image_bytes = image_response.content | |
| image = Image.open(io.BytesIO(image_bytes)) | |
| return image | |
| # Streamlit interface for user inputs and displaying outputs | |
| st.title("Morpheus - Dreams Generator") | |
| st.write("Enter your feelings and moments of the day to generate a summarization along with an AI-generated image!") | |
| inputs = st.text_area("Enter your emotions, expressions, best and worst moments of the day:", height=200, value="Today was a mix of emotions. I felt happy in the morning but sad in the evening. The best moment was meeting a friend, and the worst was a stressful meeting.") | |
| if st.button("Generate Summary and Image"): | |
| summary = generate_text_summary(inputs) | |
| st.write("Summary:", summary) | |
| with st.spinner("Generating Image..."): | |
| image = generate_image(inputs) | |
| st.image(image, caption="Generated Image", use_column_width=True) | |