alakxender commited on
Commit
76fc39a
·
1 Parent(s): 3bd94eb
Files changed (1) hide show
  1. app.py +60 -24
app.py CHANGED
@@ -1,8 +1,9 @@
1
  # Import necessary libraries
 
2
  import torch
3
  import spaces
4
  from transformers import AutoTokenizer, AutoConfig, AutoModelForCausalLM, pipeline
5
- import gradio as gr
6
 
7
  # Load Goldfish model for Dhivehi
8
  model_name = 'div_thaa_full'
@@ -29,31 +30,66 @@ def generate_text(input_text):
29
 
30
  # Create Gradio interface
31
 
32
- styles = """
33
- .thaana textarea {
 
34
  font-size: 18px !important;
35
- font-family: 'MV_Faseyha', 'Faruma', 'A_Faruma', 'Noto Sans Thaana', 'MV Boli';
36
  line-height: 1.8 !important;
 
37
  }
38
  """
39
 
40
- demo = gr.Interface(
41
- fn=generate_text,
42
- css=styles,
43
- inputs=gr.Textbox(lines=2, label="Enter Dhivehi Text", rtl=True, elem_classes="thaana"),
44
- outputs=gr.Textbox(lines=2, rtl=True, elem_classes="thaana"),
45
- title="Demo Dhivehi Text Generator",
46
- description="Generate text in Dhivehi language. This model is trained to generate coherent text based on the input prompt.",
47
- article="<p>Model: Goldfish is a suite of monolingual language models trained for 350 languages. This model is the Dhivehi (Thaana script). For more details, visit the <a href='https://github.com/tylerachang/goldfish' target='_blank'>Goldfish Models GitHub repository</a>.</p>",
48
- examples=[
49
- ["ދިވެހިރާއްޖެ"],
50
- ["އެމެރިކާ އިންތިޚާބު"],
51
- ["ސަލާމް"],
52
- ["ދުނިޔޭގެ ސިއްޙަތު ޖަމްޢިއްޔާ"],
53
- ["ޤަދީމީ ސަގާފަތް"],
54
- ["ޑިމޮކްރަސީ"]
55
- ]
56
- )
57
-
58
- # Launch the app
59
- demo.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  # Import necessary libraries
2
+ import gradio as gr
3
  import torch
4
  import spaces
5
  from transformers import AutoTokenizer, AutoConfig, AutoModelForCausalLM, pipeline
6
+
7
 
8
  # Load Goldfish model for Dhivehi
9
  model_name = 'div_thaa_full'
 
30
 
31
  # Create Gradio interface
32
 
33
+ # Custom CSS with modern Gradio styling
34
+ custom_css = """
35
+ .thaana-textbox textarea {
36
  font-size: 18px !important;
37
+ font-family: 'MV_Faseyha', 'Faruma', 'A_Faruma', 'Noto Sans Thaana', 'MV Boli' !important;
38
  line-height: 1.8 !important;
39
+ direction: rtl !important;
40
  }
41
  """
42
 
43
+ # Example inputs
44
+ examples = [
45
+ ["ދިވެހިރާއްޖެ"],
46
+ ["އެމެރިކާ އިންތިޚާބު"],
47
+ ["ސަލާމް"],
48
+ ["ދުނިޔޭގެ ސިއްޙަތު ޖަމްޢިއްޔާ"],
49
+ ["ޤަދީމީ ސަގާފަތް"],
50
+ ["ޑިމޮކްރަސީ"]
51
+ ]
52
+
53
+ # Create Gradio app with modern components
54
+ with gr.Blocks(css=custom_css) as demo:
55
+ gr.Markdown("# Demo Dhivehi Text Generator")
56
+ gr.Markdown("Generate text in Dhivehi language. This model is trained to generate coherent text based on the input prompt.")
57
+
58
+ with gr.Row():
59
+ input_text = gr.Textbox(
60
+ label="Enter Dhivehi Text",
61
+ lines=2,
62
+ elem_classes=["thaana-textbox"],
63
+ rtl=True
64
+ )
65
+ output_text = gr.Textbox(
66
+ label="Generated Text",
67
+ lines=2,
68
+ elem_classes=["thaana-textbox"],
69
+ rtl=True
70
+ )
71
+
72
+ generate_btn = gr.Button("Generate")
73
+ generate_btn.click(
74
+ fn=generate_text,
75
+ inputs=input_text,
76
+ outputs=output_text
77
+ )
78
+
79
+ gr.Examples(
80
+ examples=examples,
81
+ inputs=input_text,
82
+ outputs=output_text,
83
+ fn=generate_text,
84
+ cache_examples=True
85
+ )
86
+
87
+ gr.Markdown("""
88
+ ### Model Information
89
+ Model: Goldfish is a suite of monolingual language models trained for 350 languages.
90
+ This model is the Dhivehi (Thaana script). For more details, visit the
91
+ [Goldfish Models GitHub repository](https://github.com/tylerachang/goldfish).
92
+ """)
93
+
94
+ if __name__ == "__main__":
95
+ demo.launch()