Spaces:
Runtime error
Runtime error
Download app.py from SpawnedShoyo/0_0: direct link, hf CLI and curl.
- Browser
- Download file 1.01 kB
-
https://huggingface.co/spaces/SpawnedShoyo/0_0/resolve/main/app.py
- Command line
-
hf download hf://spaces/SpawnedShoyo/0_0/app.py
-
curl -L -o app.py https://huggingface.co/spaces/SpawnedShoyo/0_0/resolve/main/app.py
1.01 kB
| import gradio as gr | |
| from transformers import BlenderbotForConditionalGeneration, BlenderbotTokenizer | |
| # Load the pre-trained Blenderbot model and tokenizer | |
| model = BlenderbotForConditionalGeneration.from_pretrained("facebook/blenderbot-400M-distill") | |
| tokenizer = BlenderbotTokenizer.from_pretrained("facebook/blenderbot-400M-distill") | |
| # Define the chatbot function | |
| def chatbot(input_text): | |
| input_ids = tokenizer.encode(input_text, return_tensors="pt") | |
| bot_input_ids = input_ids | |
| chatbot_response = model.generate(bot_input_ids, max_length=1000, num_return_sequences=1, pad_token_id=tokenizer.eos_token_id) | |
| response_text = tokenizer.decode(chatbot_response[0], skip_special_tokens=True) | |
| return response_text | |
| # Create the Gradio interface | |
| iface = gr.Interface(fn=chatbot, | |
| inputs="text", | |
| outputs="text", | |
| title="Chatbot using Hugging Face Transformers", | |
| description="Ask me anything!") | |
| iface.launch(share=True) |