p208p2002 commited on
Commit
8c2fd38
β€’
1 Parent(s): 20a2635
react-qa/build/asset-manifest.json CHANGED
@@ -1,15 +1,15 @@
1
  {
2
  "files": {
3
  "main.css": "/embed/p208p2002/Transformer-QA-Decode-Visualize/static/css/main.572222cd.css",
4
- "main.js": "/embed/p208p2002/Transformer-QA-Decode-Visualize/static/js/main.564be008.js",
5
  "static/js/787.e7ee5088.chunk.js": "/embed/p208p2002/Transformer-QA-Decode-Visualize/static/js/787.e7ee5088.chunk.js",
6
  "index.html": "/embed/p208p2002/Transformer-QA-Decode-Visualize/index.html",
7
  "main.572222cd.css.map": "/embed/p208p2002/Transformer-QA-Decode-Visualize/static/css/main.572222cd.css.map",
8
- "main.564be008.js.map": "/embed/p208p2002/Transformer-QA-Decode-Visualize/static/js/main.564be008.js.map",
9
  "787.e7ee5088.chunk.js.map": "/embed/p208p2002/Transformer-QA-Decode-Visualize/static/js/787.e7ee5088.chunk.js.map"
10
  },
11
  "entrypoints": [
12
  "static/css/main.572222cd.css",
13
- "static/js/main.564be008.js"
14
  ]
15
  }
 
1
  {
2
  "files": {
3
  "main.css": "/embed/p208p2002/Transformer-QA-Decode-Visualize/static/css/main.572222cd.css",
4
+ "main.js": "/embed/p208p2002/Transformer-QA-Decode-Visualize/static/js/main.3fe1a009.js",
5
  "static/js/787.e7ee5088.chunk.js": "/embed/p208p2002/Transformer-QA-Decode-Visualize/static/js/787.e7ee5088.chunk.js",
6
  "index.html": "/embed/p208p2002/Transformer-QA-Decode-Visualize/index.html",
7
  "main.572222cd.css.map": "/embed/p208p2002/Transformer-QA-Decode-Visualize/static/css/main.572222cd.css.map",
8
+ "main.3fe1a009.js.map": "/embed/p208p2002/Transformer-QA-Decode-Visualize/static/js/main.3fe1a009.js.map",
9
  "787.e7ee5088.chunk.js.map": "/embed/p208p2002/Transformer-QA-Decode-Visualize/static/js/787.e7ee5088.chunk.js.map"
10
  },
11
  "entrypoints": [
12
  "static/css/main.572222cd.css",
13
+ "static/js/main.3fe1a009.js"
14
  ]
15
  }
react-qa/build/index.html CHANGED
@@ -1 +1 @@
1
- <!doctype html><html lang="en"><head><meta charset="utf-8"/><link rel="icon" href="/embed/p208p2002/Transformer-QA-Decode-Visualize/favicon.ico"/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="#000000"/><meta name="description" content="Web site created using create-react-app"/><link rel="apple-touch-icon" href="/embed/p208p2002/Transformer-QA-Decode-Visualize/logo192.png"/><link rel="manifest" href="/embed/p208p2002/Transformer-QA-Decode-Visualize/manifest.json"/><title>React App</title><script defer="defer" src="/embed/p208p2002/Transformer-QA-Decode-Visualize/static/js/main.564be008.js"></script><link href="/embed/p208p2002/Transformer-QA-Decode-Visualize/static/css/main.572222cd.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div></body></html>
 
1
+ <!doctype html><html lang="en"><head><meta charset="utf-8"/><link rel="icon" href="/embed/p208p2002/Transformer-QA-Decode-Visualize/favicon.ico"/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="#000000"/><meta name="description" content="Web site created using create-react-app"/><link rel="apple-touch-icon" href="/embed/p208p2002/Transformer-QA-Decode-Visualize/logo192.png"/><link rel="manifest" href="/embed/p208p2002/Transformer-QA-Decode-Visualize/manifest.json"/><title>React App</title><script defer="defer" src="/embed/p208p2002/Transformer-QA-Decode-Visualize/static/js/main.3fe1a009.js"></script><link href="/embed/p208p2002/Transformer-QA-Decode-Visualize/static/css/main.572222cd.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div></body></html>
react-qa/build/static/js/main.3fe1a009.js ADDED
The diff for this file is too large to render. See raw diff
 
react-qa/build/static/js/{main.564be008.js.LICENSE.txt β†’ main.3fe1a009.js.LICENSE.txt} RENAMED
@@ -4,6 +4,15 @@ object-assign
4
  @license MIT
5
  */
6
 
 
 
 
 
 
 
 
 
 
7
  /**
8
  * @license React
9
  * react-dom.production.min.js
 
4
  @license MIT
5
  */
6
 
7
+ /**
8
+ * @license
9
+ * Lodash <https://lodash.com/>
10
+ * Copyright OpenJS Foundation and other contributors <https://openjsf.org/>
11
+ * Released under MIT license <https://lodash.com/license>
12
+ * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
13
+ * Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
14
+ */
15
+
16
  /**
17
  * @license React
18
  * react-dom.production.min.js
react-qa/build/static/js/main.3fe1a009.js.map ADDED
The diff for this file is too large to render. See raw diff
 
react-qa/build/static/js/main.564be008.js DELETED
The diff for this file is too large to render. See raw diff
 
react-qa/build/static/js/main.564be008.js.map DELETED
The diff for this file is too large to render. See raw diff
 
react-qa/src/App.js CHANGED
@@ -1,124 +1,141 @@
1
  import { HlList, HlLayerContainer, HlLayer } from 'react-transformer-qa-decode-visualize'
2
  import 'react-transformer-qa-decode-visualize/dist/index.css'
3
- import { useState,useEffect } from 'react'
 
4
 
5
  const axios = require('axios').default;
6
  function App() {
7
 
8
- const [qa_data, set_qa_data] = useState([[]])
9
- const [question, set_question] = useState("Who is the bad guy ?")
10
- const [context, set_context] = useState("Harry Potter is a series of seven fantasy novels written by British author J. K. Rowling. The novels chronicle the lives of a young wizard, Harry Potter, and his friends Hermione Granger and Ron Weasley, all of whom are students at Hogwarts School of Witchcraft and Wizardry. The main story arc concerns Harry's struggle against Lord Voldemort, a dark wizard who intends to become immortal, overthrow the wizard governing body known as the Ministry of Magic and subjugate all wizards and Muggles (non-magical people).")
 
11
 
12
- let request_qa_data = (e,_question=question,_context=context) => {
13
- const { REACT_APP_IN_DEV = 'false' } = process.env;
14
- let api_url = 'https://hf.space/embed/p208p2002/Transformer-QA-Decode-Visualize/question-answer'
15
- if (REACT_APP_IN_DEV === 'true') {
16
- api_url = 'http://127.0.0.1:7860/question-answer'
 
 
 
 
 
 
 
 
 
 
 
17
  }
18
- axios.post(api_url, {
19
- question:_question,
20
- context:_context
21
- })
22
- .then(function (response) {
23
- console.log(response.data)
24
- set_qa_data(response.data)
25
- })
26
- }
27
-
28
-
29
- useEffect(()=>{
30
- request_qa_data(undefined,question,context) // eslint-disable-next-line
31
- },[])
32
-
33
- return (
34
- <div style={{ width: 800, padding: 20 }}>
35
-
36
- <h4>Question</h4>
37
- <input
38
- style={{ width: 600 }}
39
- type="text"
40
- value={question}
41
- onChange={(e) => {
42
- set_question(e.target.value)
43
- request_qa_data(e,e.target.value)
44
- }}
45
- />
46
- <br />
47
- <h4>Context</h4>
48
- <textarea
49
- name=""
50
- id=""
51
- cols="80"
52
- rows="8"
53
- value={context}
54
- onChange={(e) => {
55
- set_context(e.target.value)
56
- set_qa_data([[]])
57
- }}
58
- />
59
-
60
- <br /><br />
61
- <button
62
- type="submit"
63
- onClick={request_qa_data}
64
- >Submit
65
- </button>
66
-
67
- <br />
68
- <hr />
69
- {
70
- qa_data.map((stride_qa_data, i) => {
71
- stride_qa_data = stride_qa_data.slice(0, 5)
72
- stride_qa_data = stride_qa_data.map((data) => {
73
-
74
- if (data.global_context_start === 0 && data.global_context_end === 0) {
75
- data.answer_span = "** NO_ANSWER **"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
76
  }
77
- const answer_text = data.answer_span
78
- data.answer_span = `logit:${data.start_logit.toFixed(2)}, ${data.end_logit.toFixed(2).padStart(4)} - ${answer_text}`
79
-
80
- return data
81
- })
82
- return (
83
- <div key={i}>
84
- <div>
85
- <h4>Transformer QA Model <small>(stride: {i + 1})</small></h4>
86
- <p>{question}</p>
87
-
88
- <HlList
89
- data={{
90
- result: stride_qa_data
91
- }}
92
- color='#fc7703' />
93
- <hr />
94
- </div>
95
-
96
- <h4>Context</h4>
97
- <HlLayerContainer
98
- context={context}>
99
- <HlLayer
100
- data={{
101
- result: stride_qa_data,
102
- context: context
103
- }}
104
- color='#fc7703'
105
- />
106
- <HlLayer
107
- data={{
108
- result: stride_qa_data.slice(0, 1),
109
- context: context
110
- }}
111
- color='red'
112
- />
113
- </HlLayerContainer >
114
  </div>
115
- )
116
- })
117
- }
118
 
119
 
120
- </div>
121
- );
122
  }
123
 
124
  export default App;
 
1
  import { HlList, HlLayerContainer, HlLayer } from 'react-transformer-qa-decode-visualize'
2
  import 'react-transformer-qa-decode-visualize/dist/index.css'
3
+ import { useState, useEffect, useCallback } from 'react'
4
+ import _ from "lodash";
5
 
6
  const axios = require('axios').default;
7
  function App() {
8
 
9
+ const [qa_data, set_qa_data] = useState([[]])
10
+ const [question, set_question] = useState("Who is the bad guy ?")
11
+ const [context, set_context] = useState("Harry Potter is a series of seven fantasy novels written by British author J. K. Rowling. The novels chronicle the lives of a young wizard, Harry Potter, and his friends Hermione Granger and Ron Weasley, all of whom are students at Hogwarts School of Witchcraft and Wizardry. The main story arc concerns Harry's struggle against Lord Voldemort, a dark wizard who intends to become immortal, overthrow the wizard governing body known as the Ministry of Magic and subjugate all wizards and Muggles (non-magical people).")
12
+ const [is_wait_for_data, set_is_wait_for_data] = useState(true)
13
 
14
+ let request_qa_data = (e, _question = question, _context = context) => {
15
+ set_is_wait_for_data(true)
16
+ const { REACT_APP_IN_DEV = 'false' } = process.env;
17
+ let api_url = 'https://hf.space/embed/p208p2002/Transformer-QA-Decode-Visualize/question-answer'
18
+ if (REACT_APP_IN_DEV === 'true') {
19
+ api_url = 'http://127.0.0.1:7860/question-answer'
20
+ }
21
+ axios.post(api_url, {
22
+ question: _question,
23
+ context: _context
24
+ })
25
+ .then(function (response) {
26
+ console.log(response.data)
27
+ set_qa_data(response.data)
28
+ set_is_wait_for_data(false)
29
+ })
30
  }
31
+
32
+
33
+ useEffect(() => {
34
+ request_qa_data(undefined, question, context) // eslint-disable-next-line
35
+ }, [])
36
+
37
+ // eslint-disable-next-line
38
+ const debounce = useCallback(
39
+ _.debounce((e) => {
40
+ request_qa_data(e, e.target.value)
41
+ }, 250),
42
+ []
43
+ );
44
+
45
+ return (
46
+ <div style={{ width: 800, padding: 20 }}>
47
+
48
+ <h4>Question</h4>
49
+ <input
50
+ style={{ width: 600 }}
51
+ type="text"
52
+ value={question}
53
+ onChange={(e) => {
54
+ set_is_wait_for_data(true)
55
+ set_question(e.target.value)
56
+ debounce(e)
57
+ }}
58
+ />
59
+ <br />
60
+ <h4>Context</h4>
61
+ <textarea
62
+ name=""
63
+ id=""
64
+ cols="80"
65
+ rows="8"
66
+ value={context}
67
+ onChange={(e) => {
68
+ set_context(e.target.value)
69
+ set_qa_data([[]])
70
+ }}
71
+ />
72
+
73
+ <br /><br />
74
+ <button
75
+ type="submit"
76
+ onClick={request_qa_data}
77
+ >Submit
78
+ </button>
79
+
80
+ <br />
81
+ <hr />
82
+ <div className="show-result" key={JSON.stringify(qa_data)}>
83
+ {
84
+ qa_data.map((stride_qa_data, i) => {
85
+ stride_qa_data = stride_qa_data.slice(0, 5)
86
+ stride_qa_data = stride_qa_data.map((data) => {
87
+
88
+ if (data.global_context_start === 0 && data.global_context_end === 0) {
89
+ data.answer_span = "** NO_ANSWER **"
90
+ }
91
+ const answer_text = data.answer_span
92
+ data.answer_span = `logit:${data.start_logit.toFixed(2)}, ${data.end_logit.toFixed(2).padStart(4)} - ${answer_text}`
93
+
94
+ return data
95
+ })
96
+ return (
97
+ <div key={i}>
98
+ <div>
99
+ <h4>Transformer QA Model <small>(stride: {i + 1})</small></h4>
100
+ <p>{question}</p>
101
+ {is_wait_for_data ? <p style={{height:100,margin:0}}>Loading...</p> :
102
+ <HlList
103
+ data={{ result: stride_qa_data }}
104
+ color='#fc7703'
105
+ />
106
+ }
107
+ <hr />
108
+ </div>
109
+
110
+ <h4>Context</h4>
111
+ <HlLayerContainer
112
+ context={context}>
113
+ <HlLayer
114
+ data={{
115
+ result: stride_qa_data,
116
+ context: context
117
+ }}
118
+ color='#fc7703'
119
+ />
120
+ <HlLayer
121
+ data={{
122
+ result: stride_qa_data.slice(0, 1),
123
+ context: context
124
+ }}
125
+ color='red'
126
+ />
127
+ </HlLayerContainer >
128
+ </div>
129
+ )
130
+ })
131
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
132
  </div>
133
+
134
+
 
135
 
136
 
137
+ </div>
138
+ );
139
  }
140
 
141
  export default App;