Mr-Vicky-01 commited on
Commit
69ad934
·
verified ·
1 Parent(s): 72f011e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -8
app.py CHANGED
@@ -1,6 +1,6 @@
1
  from PIL import Image
2
  from transformers import BlipProcessor, BlipForConditionalGeneration
3
- from langchain import LLMChain, PromptTemplate
4
  import gradio as gr
5
  import numpy as np
6
  import requests
@@ -20,16 +20,16 @@ def generate_caption_from_image(image_path):
20
 
21
  def generate_story_from_caption(caption):
22
  # Generate story based on caption
23
- llm = HuggingFaceHub(huggingfacehub_api_token = os.getenv('HUGGING_FACE')}"},
24
- repo_id = "tiiuae/falcon-7b-instruct",
25
- verbose = False,
26
- model_kwargs = {"temperature":0.2, "max_new_tokens": 4000})
27
- template="""You are a story teller.
28
- You get a scenario as an input text, and generates a short story out of it.
29
  Context: {scenario}
30
  Story:"""
31
  prompt = PromptTemplate(template=template, input_variables=["scenario"])
32
- #Let's create our LLM chain now
33
  chain = LLMChain(prompt=prompt, llm=llm)
34
  story = chain.run(caption)
35
  start_index = story.find("Story:") + len("Story:")
 
1
  from PIL import Image
2
  from transformers import BlipProcessor, BlipForConditionalGeneration
3
+ from langchain import HuggingFaceHub, LLMChain, PromptTemplate
4
  import gradio as gr
5
  import numpy as np
6
  import requests
 
20
 
21
  def generate_story_from_caption(caption):
22
  # Generate story based on caption
23
+ llm = HuggingFaceModel(api_token=os.getenv('HUGGING_FACE_API_TOKEN'),
24
+ repo_id="tiiuae/falcon-7b-instruct",
25
+ verbose=False,
26
+ model_kwargs={"temperature": 0.2, "max_new_tokens": 4000})
27
+ template = """You are a story teller.
28
+ You get a scenario as an input text, and generate a short story out of it.
29
  Context: {scenario}
30
  Story:"""
31
  prompt = PromptTemplate(template=template, input_variables=["scenario"])
32
+ # Let's create our LLM chain now
33
  chain = LLMChain(prompt=prompt, llm=llm)
34
  story = chain.run(caption)
35
  start_index = story.find("Story:") + len("Story:")