Gayatrikh16 commited on
Commit
0bb04ea
·
verified ·
1 Parent(s): f6933d7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +52 -44
app.py CHANGED
@@ -1,47 +1,55 @@
 
 
1
  import streamlit as st
2
  from transformers import pipeline
3
 
4
- # Initialize the Hugging Face pipeline
5
- pipe = pipeline("text-generation", model="mistralai/mathstral-7B-v0.1")
6
-
7
- # Function to get response from the model
8
- def get_response(input_text, keywords, blog_style, max_new_tokens=250):
9
- # Prompt Template
10
- template = """
11
- Generate technical project ideas for {blog_style} job profile for a topic {input_text} using these keywords: {keywords}.
12
- """
13
-
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
21
- st.set_page_config(page_title="Generate Project Idea",
22
- page_icon='🤖',
23
- layout='centered',
24
- initial_sidebar_state='collapsed')
25
-
26
- st.header("Generate Project Idea 🤖")
27
-
28
- input_text = st.text_input("Enter the Topic")
29
-
30
- # Creating two more columns for additional fields
31
- col1, col2 = st.columns([5, 5])
32
-
33
- with col1:
34
- keywords = st.text_input('Keywords')
35
- with col2:
36
- blog_style = st.selectbox('Generating project idea for',
37
- ('Researchers', 'Data Scientist', 'Software Developer', 'Common People'), index=0)
38
-
39
-
40
-
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)
 
 
 
 
 
 
 
1
+ from dotenv import load_dotenv
2
+ import os
3
  import streamlit as st
4
  from transformers import pipeline
5
 
6
+ # Load environment variables from .env file
7
+ load_dotenv()
8
+
9
+ # Get the Hugging Face API token from environment variables
10
+ hf_token = os.getenv("textgen")
11
+
12
+ if not hf_token:
13
+ st.error("Hugging Face API token is not set. Please set the HUGGINGFACE_HUB_TOKEN environment variable.")
14
+ else:
15
+ # Initialize the Hugging Face pipeline with authentication
16
+ pipe = pipeline("text-generation", model="mistralai/mathstral-7B-v0.1", use_auth_token=hf_token)
17
+
18
+ # Function to get response from the model
19
+ def get_response(input_text, keywords, blog_style, max_new_tokens=250):
20
+ # Prompt Template
21
+ template = """
22
+ Generate technical project ideas for {blog_style} job profile for a topic {input_text} using these keywords: {keywords}.
23
+ """
24
+
25
+ prompt = template.format(blog_style=blog_style, input_text=input_text, keywords=keywords)
26
+
27
+ # Generate the response from the model
28
+ response = pipe(prompt, max_new_tokens=max_new_tokens)
29
+ return response[0]['generated_text'] # Extract the generated text
30
+
31
+ # Streamlit configuration
32
+ st.set_page_config(page_title="Generate Project Idea",
33
+ page_icon='🤖',
34
+ layout='centered',
35
+ initial_sidebar_state='collapsed')
36
+
37
+ st.header("Generate Project Idea 🤖")
38
+
39
+ input_text = st.text_input("Enter the Topic")
40
+
41
+ # Creating two more columns for additional fields
42
+ col1, col2 = st.columns([5, 5])
43
+
44
+ with col1:
45
+ keywords = st.text_input('Keywords')
46
+ with col2:
47
+ blog_style = st.selectbox('Generating project idea for',
48
+ ('Researchers', 'Data Scientist', 'Software Developer', 'Common People'), index=0)
49
+
50
+ submit = st.button("Generate")
51
+
52
+ # Final response
53
+ if submit:
54
+ response = get_response(input_text, keywords, blog_style)
55
+ st.write(response)