Kvikontent commited on
Commit
62f0305
1 Parent(s): dfb729f

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +41 -0
app.py ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
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
+ # Streamlit interface for user inputs and displaying outputs
30
+ st.title("Morpheus - Dreams Generator")
31
+ st.write("Enter your feelings and moments of the day to generate a summarization along with an AI-generated image!")
32
+
33
+ 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.")
34
+
35
+ if st.button("Generate Summary and Image"):
36
+ summary = generate_text_summary(inputs)
37
+ st.write("Summary:", summary)
38
+
39
+ with st.spinner("Generating Image..."):
40
+ image = generate_image(inputs)
41
+ st.image(image, caption="Generated Image", use_column_width=True)