Update app.py
Browse files
app.py
CHANGED
@@ -11,6 +11,7 @@ import warnings
|
|
11 |
warnings.filterwarnings("ignore")
|
12 |
|
13 |
# Image-to-text
|
|
|
14 |
def img2txt(url):
|
15 |
print("Initializing captioning model...")
|
16 |
captioning_model = pipeline("image-to-text", model="Salesforce/blip-image-captioning-base")
|
@@ -22,6 +23,7 @@ def img2txt(url):
|
|
22 |
return text
|
23 |
|
24 |
# Text-to-story
|
|
|
25 |
def txt2story(img_text, top_k, top_p, temperature):
|
26 |
|
27 |
headers = {"Authorization": f"Bearer {os.environ['TOGETHER_API_KEY']}"}
|
@@ -45,6 +47,7 @@ def txt2story(img_text, top_k, top_p, temperature):
|
|
45 |
|
46 |
|
47 |
# Text-to-speech
|
|
|
48 |
def txt2speech(text):
|
49 |
print("Initializing text-to-speech conversion...")
|
50 |
API_URL = "https://api-inference.huggingface.co/models/espnet/kan-bayashi_ljspeech_vits"
|
@@ -80,7 +83,6 @@ def main():
|
|
80 |
st.image(uploaded_file, caption='🖼️ Uploaded Image', use_column_width=True)
|
81 |
|
82 |
# Initiates AI processing and story generation
|
83 |
-
@spaces.GPU
|
84 |
with st.spinner("## 🤖 AI is at Work! "):
|
85 |
scenario = img2txt("uploaded_image.jpg") # Extracts text from the image
|
86 |
story = txt2story(scenario, top_k, top_p, temperature) # Generates a story based on the image text, LLM params
|
|
|
11 |
warnings.filterwarnings("ignore")
|
12 |
|
13 |
# Image-to-text
|
14 |
+
@spaces.GPU
|
15 |
def img2txt(url):
|
16 |
print("Initializing captioning model...")
|
17 |
captioning_model = pipeline("image-to-text", model="Salesforce/blip-image-captioning-base")
|
|
|
23 |
return text
|
24 |
|
25 |
# Text-to-story
|
26 |
+
@spaces.GPU
|
27 |
def txt2story(img_text, top_k, top_p, temperature):
|
28 |
|
29 |
headers = {"Authorization": f"Bearer {os.environ['TOGETHER_API_KEY']}"}
|
|
|
47 |
|
48 |
|
49 |
# Text-to-speech
|
50 |
+
@spaces.GPU
|
51 |
def txt2speech(text):
|
52 |
print("Initializing text-to-speech conversion...")
|
53 |
API_URL = "https://api-inference.huggingface.co/models/espnet/kan-bayashi_ljspeech_vits"
|
|
|
83 |
st.image(uploaded_file, caption='🖼️ Uploaded Image', use_column_width=True)
|
84 |
|
85 |
# Initiates AI processing and story generation
|
|
|
86 |
with st.spinner("## 🤖 AI is at Work! "):
|
87 |
scenario = img2txt("uploaded_image.jpg") # Extracts text from the image
|
88 |
story = txt2story(scenario, top_k, top_p, temperature) # Generates a story based on the image text, LLM params
|