Srikar00007 commited on
Commit
6580fd3
·
verified ·
1 Parent(s): 6efa785

Update src/App.js

Browse files
Files changed (1) hide show
  1. src/App.js +78 -17
src/App.js CHANGED
@@ -1,23 +1,84 @@
1
- import logo from './logo.svg';
2
- import './App.css';
3
 
4
  function App() {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
  return (
6
- <div className="App">
7
- <header className="App-header">
8
- <img src={logo} className="App-logo" alt="logo" />
9
- <p>
10
- Edit <code>src/App.js</code> and save to reload.
11
- </p>
12
- <a
13
- className="App-link"
14
- href="https://reactjs.org"
15
- target="_blank"
16
- rel="noopener noreferrer"
17
- >
18
- Learn React
19
- </a>
20
- </header>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
  </div>
22
  );
23
  }
 
1
+ import React, { useState } from "react";
2
+ import "./App.css";
3
 
4
  function App() {
5
+
6
+ const API = "https://<YOUR_SPACE_NAME>.hf.space";
7
+
8
+ const [image, setImage] = useState(null);
9
+ const [analysis, setAnalysis] = useState(null);
10
+ const [question, setQuestion] = useState("");
11
+ const [answer, setAnswer] = useState("");
12
+
13
+ async function uploadImage(e) {
14
+ const file = e.target.files[0];
15
+ setImage(URL.createObjectURL(file));
16
+
17
+ const formData = new FormData();
18
+ formData.append("file", file);
19
+
20
+ const res = await fetch(`${API}/analyze-image/`, {
21
+ method: "POST",
22
+ body: formData,
23
+ });
24
+
25
+ const data = await res.json();
26
+ setAnalysis(data);
27
+ }
28
+
29
+ async function askAI() {
30
+ const res = await fetch(`${API}/ask-ai/`, {
31
+ method: "POST",
32
+ headers: { "Content-Type": "application/json" },
33
+ body: JSON.stringify({
34
+ wound: analysis.wound_label,
35
+ skin: analysis.skin_label,
36
+ question: question,
37
+ }),
38
+ });
39
+
40
+ const data = await res.json();
41
+ setAnswer(data.reply);
42
+ }
43
+
44
  return (
45
+ <div className="container">
46
+
47
+ <h1>🩺 Medical Diagnosis + AI Assistant</h1>
48
+
49
+ <input type="file" accept="image/*" onChange={uploadImage} />
50
+
51
+ {image && <img src={image} alt="Uploaded" className="preview" />}
52
+
53
+ {analysis && (
54
+ <div className="results">
55
+ <h2>Detection Results</h2>
56
+ <p><b>Wound Type:</b> {analysis.wound_label}</p>
57
+ <p><b>Skin Disease:</b> {analysis.skin_label}</p>
58
+ </div>
59
+ )}
60
+
61
+ {analysis && (
62
+ <>
63
+ <h2>Ask a Medical Question</h2>
64
+
65
+ <input
66
+ type="text"
67
+ placeholder="Ask something..."
68
+ onChange={(e) => setQuestion(e.target.value)}
69
+ />
70
+
71
+ <button onClick={askAI}>Ask</button>
72
+
73
+ {answer && (
74
+ <div className="answer-box">
75
+ <h3>AI Response</h3>
76
+ <p>{answer}</p>
77
+ </div>
78
+ )}
79
+ </>
80
+ )}
81
+
82
  </div>
83
  );
84
  }