Kvikontent commited on
Commit
3ee6b12
1 Parent(s): 3eb2a18

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +42 -0
app.py ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import os
3
+ import requests
4
+ import io
5
+ from PIL import Image
6
+
7
+ api_token = os.environ.get("api_token")
8
+ API_URL_WH = "https://api-inference.huggingface.co/models/openai/whisper-large-v3"
9
+ API_URL = "https://api-inference.huggingface.co/models/ehristoforu/dalle-3-xl"
10
+ headers = {"Authorization": f"Bearer {api_token}"}
11
+ st.title("Realtime Text2Image Voice")
12
+ type = st.selectbox(
13
+ 'Choose input type',
14
+ ("Text", "Voice")
15
+ )
16
+
17
+ def imquery(payload):
18
+ response = requests.post(API_URL, headers=headers, json=payload)
19
+ return response.content
20
+
21
+ def generate_image(prompt):
22
+ image_bytes = imquery({
23
+ "inputs": prompt,
24
+ })
25
+ return image_bytes
26
+
27
+ if type == "Text":
28
+ prompt = st.text_input("Enter prompt")
29
+ out = imquery(prompt)
30
+ st.image(out)
31
+ else:
32
+ prompt = st.file_uploader("Paste your audiofile", type=["mp3", "m4a", "wav"])
33
+
34
+ def query(filename):
35
+ with open(filename, "rb") as f:
36
+ data = f.read()
37
+ response = requests.post(API_URL_WH, headers=headers, data=data)
38
+ return response.json()
39
+
40
+ output = query(prompt)
41
+ imoo = generate_image(output)
42
+ st.image(imoo)