Spaces:
Runtime error
Runtime error
File size: 1,116 Bytes
4b2a398 5de747a 4b2a398 5de747a 4b2a398 5de747a |
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 |
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
|