File size: 2,295 Bytes
62f0305
 
 
 
 
0411dc1
62f0305
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0411dc1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
62f0305
0411dc1
62f0305
 
 
0411dc1
62f0305
 
 
0411dc1
62f0305
 
 
 
0411dc1
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import streamlit as st
import requests
import os
import io
from PIL import Image
from gradio_client import Client

# 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))

    with st.spinner("Resizing Image..."):
        client_resize = Client("doevent/AnimateLCM-SVD")
        resized_image = client_resize.predict(image, api_name="/resize_image")
    
    with st.spinner("Animating Image..."):
        client_animate = Client("doevent/AnimateLCM-SVD")
        result = client_animate.predict(
            resized_image,
            0,
            True,
            1,
            5,
            1,
            1.5,
            576,
            320,
            20,
            api_name="/video"
        )
    
    return result

# 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 animated 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 Animated Image"):
    summary = generate_text_summary(inputs)
    st.write("Summary:", summary)
    
    with st.spinner("Generating Image..."):
        result = generate_image(inputs)
        st.markdown(f"")