Falcon-chatbot / app.py
Dorn4449's picture
Update app.py
10a2a4b
import os
os.system("pip install streamlit")
os.system("pip install transformers")
os.system("pip install torch")
os.system("pip install einops")
os.system("pip install accelerate")
os.system("pip install xformers")
import streamlit as st
import transformers
import torch
model = "tiiuae/falcon-7b-instruct"
tokenizer = transformers.AutoTokenizer.from_pretrained(model)
pipeline = transformers.pipeline(
"text-generation",
model=model,
tokenizer=tokenizer,
torch_dtype=torch.bfloat16,
trust_remote_code=True,
device_map="auto",
)
def main():
st.title("Girafatron Text Generation")
user_input = st.text_area("Enter your text:", "Girafatron is obsessed with giraffes, the most glorious animal on the face of this Earth. Giraftron believes all other animals are irrelevant when compared to the glorious majesty of the giraffe.\nDaniel: Hello, Girafatron!\nGirafatron:")
if st.button("Generate"):
sequences = pipeline(
user_input,
max_length=200,
do_sample=True,
top_k=10,
num_return_sequences=1,
eos_token_id=tokenizer.eos_token_id,
)
for seq in sequences:
st.write(f"Result: {seq['generated_text']}")
if __name__ == "__main__":
main()