Spaces:
Running
Running
File size: 1,374 Bytes
499bc65 3dae8d8 499bc65 7f7c945 499bc65 6dda2b5 499bc65 a9b7f18 499bc65 |
1 2 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 |
import streamlit as st
from langchain_community.llms import HuggingFaceEndpoint
from langchain.prompts import PromptTemplate
#from transformers import pipeline, set_seed
#st.set_page_config(page_title="Poetry Generaion Demo", page_icon=":robot:")
#st.header("Hey, I am your poetry generator")
st.title("❤️ Personalized Poetry Writing Tool ❤️")
theme = st.text_input("Enter the theme of the poem (eg. Rain, Sunshine, Tomato, etc.)")
style = st.text_input("Enter the style for the poem (eg. Shakespear, Little Girl, Professional, Student, etc.)")
keywords = st.text_input("Enter the keywords to be used in poem (comma-separated)")
llm = HuggingFaceEndpoint(
repo_id="microsoft/Phi-3-mini-4k-instruct",
task="text-generation",
max_new_tokens=512,
do_sample=False,
repetition_penalty=1.03,
temperature=0.6,
)
def generate_poem(theme, style, keywords):
"""Generates a poem based on user input."""
prompt = f"Write a poem about {theme} in the style of {style} using these keywords: {keywords}"
#output = generator(prompt, max_length=100, num_return_sequences=1)[0]['generated_text']
output = llm.invoke(prompt, max_length=100, num_return_sequences=1)
return output
submit = st.button("Enter to generate the Poem")
if submit:
st.subheader("Here is the poem: ")
st.write(generate_poem(theme, style, keywords))
|