Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +11 -7
src/streamlit_app.py
CHANGED
@@ -101,7 +101,7 @@ if query:
|
|
101 |
selected = data[idx]
|
102 |
|
103 |
# Show Image
|
104 |
-
st.image(selected['image'], caption="Most relevant medical image",
|
105 |
|
106 |
# Show Text
|
107 |
st.markdown(f"**Case Description:** {selected[TEXT_COLUMN]}")
|
@@ -109,13 +109,17 @@ if query:
|
|
109 |
# GPT Explanation
|
110 |
if openai.api_key:
|
111 |
prompt = f"Explain this case in plain English: {selected[TEXT_COLUMN]}"
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
|
|
|
|
|
|
117 |
)
|
118 |
-
explanation = response
|
|
|
119 |
st.markdown(f"### 🤖 Explanation by GPT:\n{explanation}")
|
120 |
else:
|
121 |
st.warning("OpenAI API key not found. Please set OPENAI_API_KEY as a secret environment variable.")
|
|
|
101 |
selected = data[idx]
|
102 |
|
103 |
# Show Image
|
104 |
+
st.image(selected['image'], caption="Most relevant medical image", use_container_width=True)
|
105 |
|
106 |
# Show Text
|
107 |
st.markdown(f"**Case Description:** {selected[TEXT_COLUMN]}")
|
|
|
109 |
# GPT Explanation
|
110 |
if openai.api_key:
|
111 |
prompt = f"Explain this case in plain English: {selected[TEXT_COLUMN]}"
|
112 |
+
from openai import OpenAI
|
113 |
+
client = OpenAI(api_key=openai.api_key)
|
114 |
+
|
115 |
+
response = client.chat.completions.create(
|
116 |
+
model="gpt-4o", # or "gpt-4" if you need the older GPT-4
|
117 |
+
messages=[{"role": "user", "content": prompt}],
|
118 |
+
temperature=0.5,
|
119 |
+
max_tokens=150
|
120 |
)
|
121 |
+
explanation = response.choices[0].message.content
|
122 |
+
|
123 |
st.markdown(f"### 🤖 Explanation by GPT:\n{explanation}")
|
124 |
else:
|
125 |
st.warning("OpenAI API key not found. Please set OPENAI_API_KEY as a secret environment variable.")
|