alexue4 commited on
Commit
0f9d981
1 Parent(s): 1c903eb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -20
app.py CHANGED
@@ -1,38 +1,29 @@
1
  import gradio as gr
2
- import transformers
3
 
4
  # Load the model
5
- model_name = "alexue4/text-normalization-ru-new"
6
- model = transformers.AutoModelForSequenceClassification.from_pretrained(model_name)
7
- tokenizer = transformers.AutoTokenizer.from_pretrained(model_name)
8
 
9
- # Define the custom function
10
  def custom_function(input_text):
11
- max_tokens = 100 # Set your desired max token limit
12
- tokens = tokenizer.tokenize(input_text)
 
 
13
 
14
- if len(tokens) > max_tokens:
15
- tokens = tokens[:max_tokens]
16
- input_text = tokenizer.convert_tokens_to_string(tokens)
17
-
18
- inputs = tokenizer(input_text, return_tensors="pt")
19
- outputs = model(**inputs)
20
- prediction = outputs.logits.argmax(dim=-1).item()
21
-
22
- return prediction
23
 
24
  examples = [
25
  ["в 2006-2010 гг. Вася учился в МГУ"],
26
  ["я купил iphone 10X за 14990 руб без 3-x часов полдень и т.д."]
27
  ]
28
 
29
- interface = gr.Interface(
30
  fn=custom_function,
31
  inputs="text",
32
  outputs="text",
33
  examples=examples
34
- )
35
 
36
- # Launch the interface
37
- interface.launch()
38
 
 
1
  import gradio as gr
 
2
 
3
  # Load the model
4
+ interface = gr.load("models/alexue4/text-normalization-ru-new")
 
 
5
 
6
+ # Function to modify the behavior (example: limiting max tokens and setting examples)
7
  def custom_function(input_text):
8
+ # Custom processing here (e.g., limit max tokens)
9
+ max_tokens = 250 # Set your desired max token limit
10
+ if len(input_text.split()) > max_tokens:
11
+ input_text = ' '.join(input_text.split()[:max_tokens])
12
 
13
+ # Call the original function from the interface
14
+ original_output = interface.predict(input_text)
15
+ return original_output
 
 
 
 
 
 
16
 
17
  examples = [
18
  ["в 2006-2010 гг. Вася учился в МГУ"],
19
  ["я купил iphone 10X за 14990 руб без 3-x часов полдень и т.д."]
20
  ]
21
 
22
+ gr.Interface(
23
  fn=custom_function,
24
  inputs="text",
25
  outputs="text",
26
  examples=examples
27
+ ).launch()
28
 
 
 
29