thanaphon commited on
Commit
50967d1
·
1 Parent(s): d3934ae

First model version

Browse files
Files changed (1) hide show
  1. app.py +78 -4
app.py CHANGED
@@ -1,9 +1,83 @@
1
  import gradio as gr
 
 
 
 
 
 
 
 
2
 
3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
 
5
- def greet(name):
6
- return "Hello " + name + "!!"
7
 
8
- iface = gr.Interface(fn=greet, inputs="text", outputs="text")
9
- iface.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
+ import pickle
3
+ import os
4
+ import numpy as np
5
+ import pandas as pd
6
+ from sklearn.model_selection import train_test_split
7
+ from sklearn.metrics import confusion_matrix
8
+ import matplotlib.pyplot as plt
9
+ import re
10
 
11
 
12
+ def deEmojify(text):
13
+ regrex_pattern = re.compile(pattern = "["
14
+ u"\U0001F600-\U0001F64F" # emoticons
15
+ u"\U0001F300-\U0001F5FF" # symbols & pictographs
16
+ u"\U0001F680-\U0001F6FF" # transport & map symbols
17
+ u"\U0001F1E0-\U0001F1FF" # flags (iOS)
18
+ u"\U00002500-\U00002BEF" # chinese char
19
+ u"\U00002702-\U000027B0"
20
+ u"\U00002702-\U000027B0"
21
+ u"\U000024C2-\U0001F251"
22
+ u"\U0001f926-\U0001f937"
23
+ u"\U00010000-\U0010ffff"
24
+ u"\u2640-\u2642"
25
+ u"\u2600-\u2B55"
26
+ u"\u200d"
27
+ u"\u23cf"
28
+ u"\u23e9"
29
+ u"\u231a"
30
+ u"\ufe0f" # dingbats
31
+ u"\u3030"
32
+ "]+", flags = re.UNICODE)
33
+ return regrex_pattern.sub(r'',text)
34
 
 
 
35
 
36
+ def clean_me(data):
37
+ data['clean_text'] = data.str.replace(r'<[^<>]*>', '', regex=True)
38
+ data['clean2_text']= data['clean_text'].str.strip().str.lower().str.replace('\r+', ' ').str.replace('\n+',' ').str.replace('\t+',' ')
39
+ data['clean3_text'] = data.apply(lambda row: deEmojify(row['clean2_text']), axis=1)
40
+ return(data)
41
+
42
+ def combine(a, b):
43
+ return a + " " + b
44
+
45
+
46
+ def mirror(x):
47
+ return x
48
+
49
+
50
+ with gr.Blocks() as demo:
51
+
52
+ txt = gr.Textbox(label="Input", lines=2)
53
+ txt_2 = gr.Textbox(label="Input 2")
54
+ txt_3 = gr.Textbox(value="", label="Output")
55
+ btn = gr.Button(value="Submit")
56
+ btn.click(combine, inputs=[txt, txt_2], outputs=[txt_3])
57
+
58
+ with gr.Row():
59
+ im = gr.Image()
60
+ im_2 = gr.Image()
61
+
62
+ btn = gr.Button(value="Mirror Image")
63
+ btn.click(mirror, inputs=[im], outputs=[im_2])
64
+
65
+ gr.Markdown("## Text Examples")
66
+ gr.Examples(
67
+ [["hi", "Adam"], ["hello", "Eve"]],
68
+ [txt, txt_2],
69
+ txt_3,
70
+ combine,
71
+ cache_examples=True,
72
+ )
73
+ gr.Markdown("## Image Examples")
74
+ gr.Examples(
75
+ examples=[os.path.join(os.path.dirname(__file__), "lion.jpg")],
76
+ inputs=im,
77
+ outputs=im_2,
78
+ fn=mirror,
79
+ cache_examples=True,
80
+ )
81
+
82
+ if __name__ == "__main__":
83
+ demo.launch()