vi108 commited on
Commit
f5df55b
·
verified ·
1 Parent(s): 317bdc9

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. 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", use_column_width=True)
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
- response = openai.ChatCompletion.create(
113
- model="gpt-4",
114
- messages=[{"role": "user", "content": prompt}],
115
- temperature=0.5,
116
- max_tokens=150
 
 
 
117
  )
118
- explanation = response["choices"][0]["message"]["content"]
 
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.")