tsbawa61 commited on
Commit
ea0fa3e
·
verified ·
1 Parent(s): 3c898bc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -0
app.py CHANGED
@@ -72,4 +72,26 @@ else:
72
  description="Enter a sentence with a [MASK] token to see the model's prediction."
73
  )
74
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
75
 
 
72
  description="Enter a sentence with a [MASK] token to see the model's prediction."
73
  )
74
 
75
+ # --- Step 4: Launch the Gradio App --- #
76
+
77
+ import gradio as gr
78
+ from transformers import pipeline
79
+
80
+ # Load a small, efficient model
81
+ generator = pipeline("text-generation", model="distilgpt2")
82
+
83
+ def generate_text(prompt):
84
+ result = generator(prompt, max_length=50, num_return_sequences=1)
85
+ return result[0]["generated_text"]
86
+
87
+ demo = gr.Interface(
88
+ fn=generate_text,
89
+ inputs="text",
90
+ outputs="text",
91
+ title="Simple LLM Demo",
92
+ description="A lightweight text generation app using DistilGPT2."
93
+ )
94
+
95
+ # Keep the app alive on Hugging Face Spaces
96
+ demo.launch(server_name="0.0.0.0", server_port=7860)
97