Spaces:
Sleeping
Sleeping
File size: 1,980 Bytes
d6200d7 ac20fb7 d6200d7 ac20fb7 d6200d7 ac20fb7 d6200d7 ac20fb7 d6200d7 ac20fb7 d6200d7 |
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 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
from langchain.prompts import PromptTemplate
from langchain.llms import CTransformers
import os
import gradio as gr
def GetLlamaResponse(topic):
llm = CTransformers(
model_type="llama",
model="llama-2-7b-chat.ggmlv3.q8_0.bin",
config={"max_new_tokens": 256, "temperature": 0.4},
)
template = """
Generate a poem for hungry natural who wish to eat a delicious {topic} within 256 words
"""
prompt = PromptTemplate(
input_variables=["topic", "word_count", "poem_style", "temperature"],
template=template,
)
response = llm(
prompt.format(
word_count=256,
poem_style='Natural',
temperature=0.4,
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))
inputs_image_url = [
gr.Textbox(type="text", label="Topic Name"),
]
outputs_result_dict = [
gr.Textbox(type="text", label="Result"),
]
interface_image_url = gr.Interface(
fn=GetLlamaResponse,
inputs=inputs_image_url,
outputs=outputs_result_dict,
title="Poem Generation",
cache_examples=False,
)
gr.TabbedInterface(
[interface_image_url],
tab_names=['Some inference']
).queue().launch() |