Spaces:
Build error
Build error
Kvikontent
commited on
Commit
•
afdd9a4
1
Parent(s):
bd903de
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import requests
|
3 |
+
import os
|
4 |
+
import io
|
5 |
+
from PIL import Image
|
6 |
+
|
7 |
+
# Get the API token from environment variable
|
8 |
+
API_TOKEN = os.environ.get("HF_API_TOKEN")
|
9 |
+
|
10 |
+
# Function to interact with Hugging Face API for text summarization
|
11 |
+
def generate_text_summary(inputs):
|
12 |
+
API_URL = "https://api-inference.huggingface.co/models/mistralai/Mixtral-8x7B-Instruct-v0.1"
|
13 |
+
headers = {"Authorization": f"Bearer {API_TOKEN}"}
|
14 |
+
|
15 |
+
response = requests.post(API_URL, headers=headers, json={"inputs": inputs})
|
16 |
+
return response.json()
|
17 |
+
|
18 |
+
# Function to interact with Hugging Face API for image generation
|
19 |
+
def generate_image(prompt):
|
20 |
+
API_URL = "https://api-inference.huggingface.co/models/Kvikontent/midjourney-v6"
|
21 |
+
headers = {"Authorization": f"Bearer {API_TOKEN}"}
|
22 |
+
|
23 |
+
image_response = requests.post(API_URL, headers=headers, json={"inputs": prompt})
|
24 |
+
image_bytes = image_response.content
|
25 |
+
image = Image.open(io.BytesIO(image_bytes))
|
26 |
+
|
27 |
+
return image
|
28 |
+
|
29 |
+
# Gradio interface for user inputs and displaying outputs
|
30 |
+
inputs = gr.Textbox(lines=5, label="Enter your emotions, expressions, best and worst moments of the day:")
|
31 |
+
outputs_text = gr.Textbox(label="Summarization of Inputs")
|
32 |
+
outputs_image = gr.Image(type="pil", label="Generated Image")
|
33 |
+
|
34 |
+
# Create Gradio app
|
35 |
+
gr.Interface(
|
36 |
+
[inputs],
|
37 |
+
[outputs_text, outputs_image],
|
38 |
+
title="Morpheus - Dreams Generator",
|
39 |
+
description="Enter your feelings and moments of the day to generate a summarization along with an AI-generated image!",
|
40 |
+
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."]],
|
41 |
+
flagging_options=[],
|
42 |
+
analytics_enabled=False,
|
43 |
+
theme="soft"
|
44 |
+
).launch()
|