GauravGajbhiye commited on
Commit
499bc65
·
verified ·
1 Parent(s): 60158ee

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -0
app.py ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from langchain.llms import HuggingFaceEndpoint
3
+ from langchain.prompts import PromptTemplate
4
+ #from transformers import pipeline, set_seed
5
+
6
+
7
+ st.title("❤️ Personalized Poetry Writing Tool ❤️")
8
+ st.set_page_config(page_title="Poetry Generaion Demo", page_icon=":robot:")
9
+ st.header("Hey, I am your poetry generator")
10
+
11
+
12
+ theme = st.text_input("Enter the theme of the poem (eg. Rain, Sunshine, Tomato, etc.)")
13
+ style = st.text_input("Enter the style for the poem (eg. Shakespear, Little Girl, Professional, Student, etc.)")
14
+ keywords = st.text_input("Enter the keywords to be used in poem (comma-separated)")
15
+
16
+ llm = HuggingFaceEndpoint(
17
+ repo_id="microsoft/Phi-3-mini-4k-instruct",
18
+ task="text-generation",
19
+ max_new_tokens=512,
20
+ do_sample=False,
21
+ repetition_penalty=1.03,
22
+ temperature=0.6,
23
+ )
24
+
25
+
26
+ def generate_poem(theme, style, keywords):
27
+ """Generates a poem based on user input."""
28
+
29
+ prompt = f"Write a poem about {theme} in the style of {style} using these keywords: {keywords}"
30
+ #output = generator(prompt, max_length=100, num_return_sequences=1)[0]['generated_text']
31
+ output = llm.invoke(prompt)
32
+ return output
33
+
34
+ submit = st.button("Enter to generate the Poem")
35
+
36
+ if submit:
37
+ st.subheader("Here is the poem: ")
38
+ st.write(generate_poem(theme, style, keywords))