Download app.py from gowthM23/___: direct link, hf CLI and curl.
- Browser
- Download file 981 Bytes
-
https://huggingface.co/spaces/gowthM23/___/resolve/main/app.py
- Command line
-
hf download hf://spaces/gowthM23/___/app.py
-
curl -L -o app.py https://huggingface.co/spaces/gowthM23/___/resolve/main/app.py
981 Bytes
| import streamlit as st | |
| from transformers import AutoTokenizer, AutoModelForCausalLM | |
| # Load the pre-trained model and tokenizer | |
| model_name = "facebook/opt-125m" | |
| tokenizer = AutoTokenizer.from_pretrained(model_name) | |
| model = AutoModelForCausalLM.from_pretrained(model_name) | |
| st.title('Text Generation with Hugging Face') | |
| # Input text | |
| input_text = st.text_input("Enter your prompt:", "sun rises in the ") | |
| if input_text: | |
| # Tokenize the input text | |
| inputs = tokenizer(input_text, return_tensors="pt") | |
| # Generate text | |
| outputs = model.generate( | |
| inputs["input_ids"], | |
| max_length=50, # Increased length for more content | |
| num_return_sequences=1, | |
| no_repeat_ngram_size=2, | |
| top_p=0.95, | |
| top_k=50, | |
| temperature=0.7 | |
| ) | |
| # Decode the generated text | |
| generated_text = tokenizer.decode(outputs[0], skip_special_tokens=True) | |
| # Display the generated text | |
| st.write("Generated Text:") | |
| st.write(generated_text) | |