Upload 2 files
Browse files- app.py +41 -0
- requirements.txt +8 -0
app.py
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
|
| 4 |
+
# Load Model
|
| 5 |
+
model_name = "AventIQ-AI/gpt2-next-word-prediction"
|
| 6 |
+
predictor = pipeline("text-generation", model=model_name)
|
| 7 |
+
|
| 8 |
+
def predict_next_word(prompt):
|
| 9 |
+
result = predictor(prompt, max_length=len(prompt.split()) + 1, num_return_sequences=1)
|
| 10 |
+
return result[0]['generated_text']
|
| 11 |
+
|
| 12 |
+
# Examples
|
| 13 |
+
examples = [
|
| 14 |
+
["Artificial intelligence is"],
|
| 15 |
+
["The future of technology"],
|
| 16 |
+
["Machine learning enables"],
|
| 17 |
+
["Deep learning models are"],
|
| 18 |
+
]
|
| 19 |
+
|
| 20 |
+
# Gradio Interface
|
| 21 |
+
def main():
|
| 22 |
+
with gr.Blocks(theme="soft") as demo:
|
| 23 |
+
gr.Markdown("""
|
| 24 |
+
# 🚀 Next-Word Prediction
|
| 25 |
+
Enter a partial sentence, and the model will predict the next word.
|
| 26 |
+
""")
|
| 27 |
+
|
| 28 |
+
with gr.Row():
|
| 29 |
+
input_text = gr.Textbox(label="Enter a sentence", placeholder="Type here...")
|
| 30 |
+
|
| 31 |
+
predict_btn = gr.Button("🔮 Predict Next Word")
|
| 32 |
+
output_text = gr.Textbox(label="Predicted Sentence", interactive=False)
|
| 33 |
+
|
| 34 |
+
predict_btn.click(predict_next_word, inputs=input_text, outputs=output_text)
|
| 35 |
+
|
| 36 |
+
gr.Examples(examples, inputs=input_text)
|
| 37 |
+
|
| 38 |
+
demo.launch()
|
| 39 |
+
|
| 40 |
+
if __name__ == "__main__":
|
| 41 |
+
main()
|
requirements.txt
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
torch
|
| 2 |
+
transformers
|
| 3 |
+
gradio
|
| 4 |
+
sentencepiece
|
| 5 |
+
torchvision
|
| 6 |
+
huggingface_hub
|
| 7 |
+
pillow
|
| 8 |
+
numpy
|