neha-ai-playground commited on
Commit
43fa18d
·
1 Parent(s): 5de747a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -10
app.py CHANGED
@@ -3,7 +3,8 @@ from pathlib import Path
3
  import streamlit as st
4
  from transformers import pipeline
5
  from dotenv import load_dotenv
6
- from langchain import PromptTemplate, LLNChain, OpenAI
 
7
  if Path(".env").is_file():
8
  load_dotenv(".env")
9
  st.set_page_config(layout="wide")
@@ -12,29 +13,29 @@ HF_TOKEN = os.getenv("HF_TOKEN")
12
  def img2Text(url):
13
  image_to_text = pipeline("image-to-text", model="Salesforce/blip-image-captioning-large")
14
  text = image_to_text(url)
15
- st.header("Caption :")
16
  st.subheader(text)
17
  print(text)
18
  return text
19
- img2Text(test-photo.png)
20
 
21
  #llm
22
  def generate_story(scenario):
23
  template = """
24
  You are a story teller;
25
- You can generate a short story based on a simple narrative, the story should be no mmomre than 20 words;
26
 
27
  CONTEXT: {scenario}
28
  STORY:
29
  """
30
 
31
  prompt = PromptTemplate(template=template,input_variables=["scenario"])
32
-
33
- story_llm = LLMChain(llm=OpenAI(
34
- model_name="gpt-3.5-turbo", temperature=1), prompt=prompt, verbose=True)
35
-
36
- story = story_llm.predict(scenario=scenario)
37
- st.header("Story :")
38
  st.subheader(story)
39
  print(story)
40
  return story
 
3
  import streamlit as st
4
  from transformers import pipeline
5
  from dotenv import load_dotenv
6
+ from langchain import PromptTemplate, HuggingFaceHub, LLMChain
7
+
8
  if Path(".env").is_file():
9
  load_dotenv(".env")
10
  st.set_page_config(layout="wide")
 
13
  def img2Text(url):
14
  image_to_text = pipeline("image-to-text", model="Salesforce/blip-image-captioning-large")
15
  text = image_to_text(url)
16
+ st.subheader("Caption :")
17
  st.subheader(text)
18
  print(text)
19
  return text
20
+ img2Text("photo.png")
21
 
22
  #llm
23
  def generate_story(scenario):
24
  template = """
25
  You are a story teller;
26
+ You can generate a short story based on a simple narrative, the story should be no momre than 20 words;
27
 
28
  CONTEXT: {scenario}
29
  STORY:
30
  """
31
 
32
  prompt = PromptTemplate(template=template,input_variables=["scenario"])
33
+ llm_chain = LLMChain(prompt=prompt,
34
+ llm=HuggingFaceHub(repo_id="google/flan-t5-xl",
35
+ model_kwargs={"temperature":0,
36
+ "max_length":64}))
37
+ story =llm_chain.run(scenario)
38
+ st.subheader("Story :")
39
  st.subheader(story)
40
  print(story)
41
  return story