File size: 2,247 Bytes
6580fd3
 
182f3f1
 
6580fd3
d37c2b2
0c67b84
6580fd3
 
 
 
 
 
d37c2b2
6580fd3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d37c2b2
6580fd3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
182f3f1
6580fd3
 
 
 
 
 
d37c2b2
6580fd3
 
d37c2b2
6580fd3
 
d37c2b2
 
6580fd3
 
 
 
d37c2b2
6580fd3
 
d37c2b2
6580fd3
 
 
 
 
 
 
 
 
 
 
d37c2b2
6580fd3
 
 
 
 
 
182f3f1
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import React, { useState } from "react";
import "./App.css";

function App() {

  // βœ… Your Hugging Face backend URL
  const API = "https://Srikar00007--Medical-Chatbot.hf.space";

  const [image, setImage] = useState(null);
  const [analysis, setAnalysis] = useState(null);
  const [question, setQuestion] = useState("");
  const [answer, setAnswer] = useState("");

  // βœ… Upload Image -> Analyze
  async function uploadImage(e) {
    const file = e.target.files[0];
    setImage(URL.createObjectURL(file));

    const formData = new FormData();
    formData.append("file", file);

    const res = await fetch(`${API}/analyze-image/`, {
      method: "POST",
      body: formData,
    });

    const data = await res.json();
    setAnalysis(data);
  }

  // βœ… Ask AI
  async function askAI() {
    const res = await fetch(`${API}/ask-ai/`, {
      method: "POST",
      headers: { "Content-Type": "application/json" },
      body: JSON.stringify({
        wound: analysis.wound_label,
        skin: analysis.skin_label,
        question: question,
      }),
    });

    const data = await res.json();
    setAnswer(data.reply);
  }

  return (
    <div className="container">

      <h1>🩺 Medical Diagnosis + AI Assistant</h1>

      <input type="file" accept="image/*" onChange={uploadImage} />

      {/* βœ… Show Uploaded Image */}
      {image && <img src={image} alt="Uploaded" className="preview" />}

      {/* βœ… Show Analysis Results */}
      {analysis && (
        <div className="results">
          <h2>πŸ” Detection Results</h2>
          <p><b>Wound:</b> {analysis.wound_label}</p>
          <p><b>Skin Disease:</b> {analysis.skin_label}</p>
        </div>
      )}

      {/* βœ… Ask Question */}
      {analysis && (
        <>
          <h2>πŸ’¬ Ask a Medical Question</h2>
          
          <input
            type="text"
            placeholder="Ask something..."
            onChange={(e) => setQuestion(e.target.value)}
          />

          <button onClick={askAI}>Ask</button>

          {answer && (
            <div className="answer-box">
              <h3>βœ… AI Response</h3>
              <p>{answer}</p>
            </div>
          )}
        </>
      )}

    </div>
  );
}

export default App;