Spaces:
Runtime error
Runtime error
import { HlList, HlLayerContainer, HlLayer } from 'react-transformer-qa-decode-visualize' | |
import 'react-transformer-qa-decode-visualize/dist/index.css' | |
import { useEffect, useState } from 'react' | |
const axios = require('axios').default; | |
function App() { | |
const [qa_data, set_qa_data] = useState([[]]) | |
const [question,set_question] = useState("What's my name?") | |
const [context,set_context] = useState("My name is Clara and I live in Berkeley.") | |
let request_qa_data = () => { | |
axios.post('http://127.0.0.1:7680/question-answer',{ | |
question, | |
context | |
}) | |
.then(function (response) { | |
console.log(response.data) | |
set_qa_data(response.data) | |
}) | |
} | |
return ( | |
<div style={{ width: 800, padding: 20 }}> | |
<h4>Question</h4> | |
<input | |
style={{ width: 600 }} | |
type="text" | |
value={question} | |
onChange={(e)=>{ | |
set_question(e.target.value) | |
set_qa_data([[]]) | |
}} | |
/> | |
<br /> | |
<h4>Context</h4> | |
<textarea | |
name="" | |
id="" | |
cols="80" | |
rows="20" | |
value={context} | |
onChange={(e)=>{ | |
set_context(e.target.value) | |
set_qa_data([[]]) | |
}} | |
/> | |
<br /><br /> | |
<button | |
type="submit" | |
onClick={request_qa_data} | |
>Submit | |
</button> | |
<br /> | |
<hr /> | |
<div> | |
<h4>Transformer QA Model</h4> | |
<p>{question}</p> | |
<HlList | |
data={{ | |
result: qa_data[0].slice(0, 10) | |
}} | |
color='yellow' /> | |
<hr /> | |
</div> | |
<h4>Context</h4> | |
<HlLayerContainer | |
context={context}> | |
<HlLayer | |
data={{ | |
result: qa_data[0].slice(0, 10), | |
context: context | |
}} | |
color='yellow' | |
/> | |
</HlLayerContainer > | |
</div> | |
); | |
} | |
export default App; | |