File size: 1,773 Bytes
afdd9a4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
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

# Gradio interface for user inputs and displaying outputs
inputs = gr.Textbox(lines=5, label="Enter your emotions, expressions, best and worst moments of the day:")
outputs_text = gr.Textbox(label="Summarization of Inputs")
outputs_image = gr.Image(type="pil", label="Generated Image")

# Create Gradio app
gr.Interface(
    [inputs],
    [outputs_text, outputs_image],
    title="Morpheus - Dreams Generator",
    description="Enter your feelings and moments of the day to generate a summarization along with an AI-generated image!",
    examples=[["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."]],
    flagging_options=[],
    analytics_enabled=False,
    theme="soft"
    ).launch()