Spaces:
Build error
Build error
File size: 1,594 Bytes
d9904c6 a46550a d9904c6 a46550a d9904c6 a46550a d9904c6 a46550a d9904c6 a46550a d9904c6 a46550a d9904c6 a46550a d9904c6 a46550a d9904c6 a46550a d9904c6 a46550a d9904c6 a46550a d9904c6 a46550a d9904c6 a46550a d9904c6 a46550a | 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 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | import streamlit as st
from langchain.prompts import PromptTemplate
from langchain.llms import CTransformers
import os
def GetLlamaResponse(word_count, poem_style, temperature, topic="pizza"):
llm = CTransformers(
model_type="llama",
model="llama-2-7b-chat.ggmlv3.q8_0.bin",
config={"max_new_tokens": 256, "temperature": temperature},
)
template = """
Generater a poem for hungry {poem_style} who wish to eat a delicious {topic} within {word_count} words
"""
prompt = PromptTemplate(
input_variables=["topic", "word_count", "poem_style", "temperature"],
template=template,
)
response = llm(
prompt.format(
word_count=word_count,
poem_style=poem_style,
temperature=temperature,
topic=topic,
)
)
return response
st.set_page_config(
page_title="Generate Poem",
page_icon=" :pizza:",
layout="centered",
initial_sidebar_state="collapsed",
)
st.header("Generate poems :pizza:")
topic = st.text_input("Enter the poem topic")
col1, col2 = st.columns([10, 10])
col3 = col3 = st.columns(1)[0]
with col1:
word_count = st.text_input("Enter number of words : ")
with col2:
poem_style = st.selectbox(
"Write the poem for", ("Michelin Tasters", "Foodies", "Laymen"), index=2
)
with col3:
temperature = st.slider(
"Select Temperature", min_value=0.0, max_value=1.0, step=0.01
)
submit = st.button("Generate poem")
if submit:
st.write(GetLlamaResponse(word_count, poem_style, temperature, topic)) |