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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -2
app.py CHANGED
@@ -3,7 +3,7 @@ from pathlib import Path
3
  import streamlit as st
4
  from transformers import pipeline
5
  from dotenv import load_dotenv
6
-
7
  if Path(".env").is_file():
8
  load_dotenv(".env")
9
  st.set_page_config(layout="wide")
@@ -12,7 +12,30 @@ 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.subheader(text)
16
  print(text)
17
  return text
18
- img2Text(test-photo.png)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
  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
41
+