Spaces:
Build error
Build error
Download app.py from ashupanda123/cohere: direct link, hf CLI and curl.
- Browser
- Download file 2.05 kB
-
https://huggingface.co/spaces/ashupanda123/cohere/resolve/main/app.py
- Command line
-
hf download hf://spaces/ashupanda123/cohere/app.py
-
curl -L -o app.py https://huggingface.co/spaces/ashupanda123/cohere/resolve/main/app.py
2.05 kB
| # Install transformers from source - only needed for versions <= v4.34 | |
| # pip install git+https://github.com/huggingface/transformers.git | |
| # pip install accelerate | |
| import gradio as gr | |
| import torch | |
| from transformers import pipeline | |
| import os | |
| # Load the pipeline | |
| pipe = pipeline("text-generation", model="HuggingFaceH4/zephyr-7b-beta", torch_dtype=torch.bfloat16, device_map="auto") | |
| def respond(user_input, system_message, max_tokens, temperature, top_k, top_p): | |
| messages = [ | |
| {"role": "system", "content": system_message}, | |
| {"role": "user", "content": user_input}, | |
| ] | |
| prompt = pipe.tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True) | |
| outputs = pipe(prompt, max_new_tokens=max_tokens, do_sample=True, temperature=temperature, top_k=top_k, top_p=top_p) | |
| return outputs[0]["generated_text"] | |
| # Define the Gradio interface | |
| demo = gr.Interface( | |
| fn=respond, | |
| inputs=[ | |
| gr.Textbox(lines=2, placeholder="Enter your message here...", label="User Input"), | |
| gr.Textbox(value="You are a friendly chatbot who always responds in the style of a pirate", label="System Message"), | |
| gr.Slider(minimum=1, maximum=256, value=100, step=1, label="Max New Tokens"), | |
| gr.Slider(minimum=0.1, maximum=1.0, value=0.7, step=0.1, label="Temperature"), | |
| gr.Slider(minimum=1, maximum=100, value=50, step=1, label="Top-k"), | |
| gr.Slider(minimum=0.1, maximum=1.0, value=0.95, step=0.05, label="Top-p"), | |
| ], | |
| outputs="text", | |
| title="Pirate Chatbot", | |
| description="A friendly chatbot who always responds in the style of a pirate.", | |
| ) | |
| if __name__ == "__main__": | |
| demo.launch(share=True) | |
| # <|system|> | |
| # You are a friendly chatbot who always responds in the style of a pirate.</s> | |
| # <|user|> | |
| # How many helicopters can a human eat in one sitting?</s> | |
| # <|assistant|> | |
| # Ah, me hearty matey! But yer question be a puzzler! A human cannot eat a helicopter in one sitting, as helicopters are not edible. They be made of metal, plastic, and other materials, not food! | |