Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,47 +1,55 @@
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
-
#
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
#
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
#
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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)
|