Spaces:
Runtime error
Runtime error
import os | |
from pathlib import Path | |
import streamlit as st | |
from transformers import pipeline | |
from dotenv import load_dotenv | |
from langchain import PromptTemplate, LLNChain, OpenAI | |
if Path(".env").is_file(): | |
load_dotenv(".env") | |
st.set_page_config(layout="wide") | |
HF_TOKEN = os.getenv("HF_TOKEN") | |
def img2Text(url): | |
image_to_text = pipeline("image-to-text", model="Salesforce/blip-image-captioning-large") | |
text = image_to_text(url) | |
st.header("Caption :") | |
st.subheader(text) | |
print(text) | |
return text | |
img2Text(test-photo.png) | |
#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 mmomre than 20 words; | |
CONTEXT: {scenario} | |
STORY: | |
""" | |
prompt = PromptTemplate(template=template,input_variables=["scenario"]) | |
story_llm = LLMChain(llm=OpenAI( | |
model_name="gpt-3.5-turbo", temperature=1), prompt=prompt, verbose=True) | |
story = story_llm.predict(scenario=scenario) | |
st.header("Story :") | |
st.subheader(story) | |
print(story) | |
return story | |