Spaces:
Runtime error
Runtime error
File size: 1,347 Bytes
4b2a398 43fa18d 5e3bd25 43fa18d 4b2a398 5e3bd25 4b2a398 5e3bd25 43fa18d 4b2a398 5e3bd25 5de747a 43fa18d 5de747a 43fa18d 5de747a 5e3bd25 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
import os
from pathlib import Path
import streamlit as st
from transformers import pipeline
from dotenv import load_dotenv
from langchain import PromptTemplate, HuggingFaceHub, LLMChain
import requests
if Path(".env").is_file():
load_dotenv(".env")
st.set_page_config(layout="wide")
HF_TOKEN = os.getenv("HUGGINGFACEHUB_API_TOKEN")
def img2Text(url):
image_to_text = pipeline("image-to-text", model="Salesforce/blip-image-captioning-large")
text = image_to_text(url)[0]["generated_text"]
st.subheader("Caption :")
st.subheader(text)
return text
img2Text("photo.jpg")
#llm
def generate_story(scenario):
template = """
You are a story teller;
You can generate a short story based on a simple narrative, the story should be no momre than 20 words;
CONTEXT: {scenario}
STORY:
"""
prompt = PromptTemplate(template=template,input_variables=["scenario"])
llm_chain = LLMChain(prompt=prompt,
llm=HuggingFaceHub(repo_id="google/flan-t5-xl",
model_kwargs={"temperature":0,
"max_length":64}))
story =llm_chain.run(scenario)
st.subheader("Story :")
st.subheader(story)
print(story)
return story
scenario = img2Text("photo.jpg")
story = generate_story(scenario) |