File size: 876 Bytes
8bc7dc5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from transformers import pipeline
from langchain.prompts import PromptTemplate
from langchain.chains import LLMChain

def img2text(url):

    image_to_text = pipeline("image-to-text", model='Salesforce/blip-image-captioning-base')

    text = image_to_text(url)

    out = text[0]['generated_text']
    
    return out


def generate_InstaCap(scenario, tone_of_voice, form, llm):
    
    instaCap_prompt = f"Craft a {form} Caption on my Instagram Image  Here is the description of my Instagram Image: {scenario}.\nThe tone should be {tone_of_voice}"
        
    instaCap_promptTemp = PromptTemplate(
    input_variables=["text_input"],
    template="You are infulencer:\n{text_input}\nInstagram Caption:")
   
    instaCap_extraction_chain = LLMChain(llm=llm, prompt=instaCap_promptTemp)
    instaCap = instaCap_extraction_chain.run(instaCap_prompt)
    
    return instaCap