Upload 2 files
Browse files- app.py +44 -0
- requirements.txt +8 -0
app.py
ADDED
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import pipeline
|
3 |
+
|
4 |
+
# Load the GPT-2 next-line prediction model
|
5 |
+
model_name = "AventIQ-AI/gpt2-lmheadmodel-next-line-prediction-model"
|
6 |
+
generator = pipeline("text-generation", model=model_name)
|
7 |
+
|
8 |
+
def generate_next_line(prompt):
|
9 |
+
"""Generates the next line of text based on the input prompt."""
|
10 |
+
if not prompt.strip():
|
11 |
+
return "⚠️ Please enter a prompt."
|
12 |
+
|
13 |
+
response = generator(prompt, max_length=len(prompt.split()) + 10, num_return_sequences=1)
|
14 |
+
return response[0]["generated_text"]
|
15 |
+
|
16 |
+
# Example Inputs
|
17 |
+
example_prompts = [
|
18 |
+
"Once upon a time, a young explorer discovered",
|
19 |
+
"The AI revolutionized the way people interacted with",
|
20 |
+
"In the distant future, humans and robots lived together in",
|
21 |
+
"The detective examined the crime scene and found a"
|
22 |
+
]
|
23 |
+
|
24 |
+
# Create Gradio UI
|
25 |
+
with gr.Blocks() as demo:
|
26 |
+
gr.Markdown("## 📝 Next-Line Prediction with GPT-2")
|
27 |
+
gr.Markdown("Enter a sentence, and the model will predict the next line!")
|
28 |
+
|
29 |
+
with gr.Row():
|
30 |
+
input_text = gr.Textbox(label="✍️ Enter your text:", placeholder="Once upon a time...")
|
31 |
+
|
32 |
+
generate_button = gr.Button("🔮 Generate Next Line")
|
33 |
+
output_text = gr.Textbox(label="📜 Generated Text:")
|
34 |
+
|
35 |
+
gr.Markdown("### ✨ Example Inputs")
|
36 |
+
example_buttons = [gr.Button(example) for example in example_prompts]
|
37 |
+
|
38 |
+
for btn in example_buttons:
|
39 |
+
btn.click(fn=lambda text=btn.value: text, outputs=input_text)
|
40 |
+
|
41 |
+
generate_button.click(generate_next_line, inputs=input_text, outputs=output_text)
|
42 |
+
|
43 |
+
# Launch the Gradio app
|
44 |
+
demo.launch()
|
requirements.txt
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
torch
|
2 |
+
transformers
|
3 |
+
gradio
|
4 |
+
sentencepiece
|
5 |
+
torchvision
|
6 |
+
huggingface_hub
|
7 |
+
pillow
|
8 |
+
numpy
|