Badhon commited on
Commit
7821f40
·
verified ·
1 Parent(s): 6d31380

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -6
app.py CHANGED
@@ -1,21 +1,31 @@
 
1
  import gradio as gr
2
  from transformers import pipeline
3
 
4
- # Load your model from Hugging Face Hub
5
  model_id = "Badhon/Bangla_punctuation_restore"
6
- punctuator = pipeline("text2text-generation", model=model_id)
7
 
8
- # Function to restore punctuation
 
 
 
 
 
 
 
9
  def restore_punctuation(text):
10
  if not text:
11
  return ""
12
- outputs = punctuator(text)
13
- return outputs[0]["generated_text"]
14
 
15
  # Gradio UI
16
  demo = gr.Interface(
17
  fn=restore_punctuation,
18
- inputs=gr.Textbox(lines=4, placeholder="Enter unpunctuated Bangla text..."),
 
 
 
19
  outputs="text",
20
  title="Bangla Punctuation Restoration",
21
  description="Type Bangla text without punctuation and get back text with punctuation restored!"
 
1
+ import os
2
  import gradio as gr
3
  from transformers import pipeline
4
 
5
+ # Model ID
6
  model_id = "Badhon/Bangla_punctuation_restore"
 
7
 
8
+ # Load model with HF token (required if model is private)
9
+ punctuator = pipeline(
10
+ "text2text-generation",
11
+ model=model_id,
12
+ token=os.getenv("HF_TOKEN")
13
+ )
14
+
15
+ # Restore punctuation
16
  def restore_punctuation(text):
17
  if not text:
18
  return ""
19
+ result = punctuator(text, max_length=256)
20
+ return result[0]["generated_text"]
21
 
22
  # Gradio UI
23
  demo = gr.Interface(
24
  fn=restore_punctuation,
25
+ inputs=gr.Textbox(
26
+ lines=4,
27
+ placeholder="Enter unpunctuated Bangla text..."
28
+ ),
29
  outputs="text",
30
  title="Bangla Punctuation Restoration",
31
  description="Type Bangla text without punctuation and get back text with punctuation restored!"