Spaces:
Runtime error
Runtime error
Commit
·
5e3bd25
1
Parent(s):
43fa18d
Update app.py
Browse files
app.py
CHANGED
@@ -4,27 +4,26 @@ import streamlit as st
|
|
4 |
from transformers import pipeline
|
5 |
from dotenv import load_dotenv
|
6 |
from langchain import PromptTemplate, HuggingFaceHub, LLMChain
|
|
|
7 |
|
8 |
if Path(".env").is_file():
|
9 |
load_dotenv(".env")
|
10 |
st.set_page_config(layout="wide")
|
11 |
-
HF_TOKEN = os.getenv("
|
12 |
|
13 |
def img2Text(url):
|
14 |
image_to_text = pipeline("image-to-text", model="Salesforce/blip-image-captioning-large")
|
15 |
-
text = image_to_text(url)
|
16 |
st.subheader("Caption :")
|
17 |
st.subheader(text)
|
18 |
-
print(text)
|
19 |
return text
|
20 |
-
img2Text("photo.
|
21 |
|
22 |
#llm
|
23 |
def generate_story(scenario):
|
24 |
template = """
|
25 |
You are a story teller;
|
26 |
You can generate a short story based on a simple narrative, the story should be no momre than 20 words;
|
27 |
-
|
28 |
CONTEXT: {scenario}
|
29 |
STORY:
|
30 |
"""
|
@@ -39,4 +38,6 @@ def generate_story(scenario):
|
|
39 |
st.subheader(story)
|
40 |
print(story)
|
41 |
return story
|
42 |
-
|
|
|
|
|
|
4 |
from transformers import pipeline
|
5 |
from dotenv import load_dotenv
|
6 |
from langchain import PromptTemplate, HuggingFaceHub, LLMChain
|
7 |
+
import requests
|
8 |
|
9 |
if Path(".env").is_file():
|
10 |
load_dotenv(".env")
|
11 |
st.set_page_config(layout="wide")
|
12 |
+
HF_TOKEN = os.getenv("HUGGINGFACEHUB_API_TOKEN")
|
13 |
|
14 |
def img2Text(url):
|
15 |
image_to_text = pipeline("image-to-text", model="Salesforce/blip-image-captioning-large")
|
16 |
+
text = image_to_text(url)[0]["generated_text"]
|
17 |
st.subheader("Caption :")
|
18 |
st.subheader(text)
|
|
|
19 |
return text
|
20 |
+
img2Text("photo.jpg")
|
21 |
|
22 |
#llm
|
23 |
def generate_story(scenario):
|
24 |
template = """
|
25 |
You are a story teller;
|
26 |
You can generate a short story based on a simple narrative, the story should be no momre than 20 words;
|
|
|
27 |
CONTEXT: {scenario}
|
28 |
STORY:
|
29 |
"""
|
|
|
38 |
st.subheader(story)
|
39 |
print(story)
|
40 |
return story
|
41 |
+
|
42 |
+
scenario = img2Text("photo.jpg")
|
43 |
+
story = generate_story(scenario)
|