Kvikontent's picture
Create app.py
afdd9a4 verified
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()