Gayatrikh16 commited on
Commit
84a9d40
·
verified ·
1 Parent(s): 9da41c7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -4
app.py CHANGED
@@ -1,12 +1,11 @@
1
  import streamlit as st
2
- from langchain.prompts import PromptTemplate
3
  from transformers import pipeline
4
 
5
  # Initialize the Hugging Face pipeline
6
  pipe = pipeline("text2text-generation", model="google/flan-t5-small")
7
 
8
  # Function to get response from the model
9
- def get_response(input_text, keywords, blog_style):
10
  # Prompt Template
11
  template = """
12
  Generate technical project ideas for {blog_style} job profile for a topic {input_text} using these keywords: {keywords}.
@@ -15,7 +14,7 @@ def get_response(input_text, keywords, blog_style):
15
  prompt = template.format(blog_style=blog_style, input_text=input_text, keywords=keywords)
16
 
17
  # Generate the response from the model
18
- response = pipe(prompt)
19
  return response[0]['generated_text'] # Extract the generated text
20
 
21
  # Streamlit configuration
@@ -37,9 +36,12 @@ with col2:
37
  blog_style = st.selectbox('Generating project idea for',
38
  ('Researchers', 'Data Scientist', 'Software Developer', 'Common People'), index=0)
39
 
 
 
 
40
  submit = st.button("Generate")
41
 
42
  # Final response
43
  if submit:
44
- response = get_response(input_text, keywords, blog_style)
45
  st.write(response)
 
1
  import streamlit as st
 
2
  from transformers import pipeline
3
 
4
  # Initialize the Hugging Face pipeline
5
  pipe = pipeline("text2text-generation", model="google/flan-t5-small")
6
 
7
  # Function to get response from the model
8
+ def get_response(input_text, keywords, blog_style, max_new_tokens=50):
9
  # Prompt Template
10
  template = """
11
  Generate technical project ideas for {blog_style} job profile for a topic {input_text} using these keywords: {keywords}.
 
14
  prompt = template.format(blog_style=blog_style, input_text=input_text, keywords=keywords)
15
 
16
  # Generate the response from the model
17
+ response = pipe(prompt, max_new_tokens=max_new_tokens)
18
  return response[0]['generated_text'] # Extract the generated text
19
 
20
  # Streamlit configuration
 
36
  blog_style = st.selectbox('Generating project idea for',
37
  ('Researchers', 'Data Scientist', 'Software Developer', 'Common People'), index=0)
38
 
39
+ # Adding an additional field for max_new_tokens
40
+ max_new_tokens = st.slider('Max New Tokens', min_value=10, max_value=100, value=50, step=10)
41
+
42
  submit = st.button("Generate")
43
 
44
  # Final response
45
  if submit:
46
+ response = get_response(input_text, keywords, blog_style, max_new_tokens)
47
  st.write(response)