Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,6 @@
|
|
1 |
import os
|
2 |
import io
|
3 |
import json
|
4 |
-
import csv
|
5 |
import asyncio
|
6 |
import xml.etree.ElementTree as ET
|
7 |
from typing import Any, Dict, Optional, Tuple, Union, List
|
@@ -150,19 +149,19 @@ def parse_pubmed_xml(xml_data: str) -> List[Dict[str, Any]]:
|
|
150 |
})
|
151 |
return articles
|
152 |
|
153 |
-
def
|
154 |
-
"""Generate
|
155 |
try:
|
156 |
response = client.chat.completions.create(
|
157 |
model="gpt-3.5-turbo",
|
158 |
-
messages=[{"role": "user", "content": f"
|
159 |
max_tokens=500,
|
160 |
temperature=0.7,
|
161 |
)
|
162 |
return response.choices[0].message.content.strip()
|
163 |
except Exception as e:
|
164 |
-
logger.error(f"
|
165 |
-
return "Failed to
|
166 |
|
167 |
###############################################################################
|
168 |
# 6) CORE FUNCTIONS #
|
@@ -176,7 +175,7 @@ def summarize_text(text: str) -> str:
|
|
176 |
response = client.chat.completions.create(
|
177 |
model="gpt-3.5-turbo",
|
178 |
messages=[{"role": "user", "content": f"Summarize this clinical data:\n{text}"}],
|
179 |
-
max_tokens=
|
180 |
temperature=0.7,
|
181 |
)
|
182 |
return response.choices[0].message.content.strip()
|
@@ -230,7 +229,7 @@ with gr.Blocks() as demo:
|
|
230 |
gr.Markdown("""
|
231 |
**Highlights**:
|
232 |
- **Summarize** clinical text (OpenAI GPT-3.5)
|
233 |
-
- **
|
234 |
- **Generate** professional PDF reports
|
235 |
""")
|
236 |
|
@@ -238,7 +237,7 @@ with gr.Blocks() as demo:
|
|
238 |
action = gr.Radio(
|
239 |
[
|
240 |
"Summarize",
|
241 |
-
"
|
242 |
"Generate Report",
|
243 |
],
|
244 |
label="Select an Action",
|
@@ -262,9 +261,9 @@ with gr.Blocks() as demo:
|
|
262 |
summary = summarize_text(combined_text)
|
263 |
return summary, None
|
264 |
|
265 |
-
elif action == "
|
266 |
-
|
267 |
-
return
|
268 |
|
269 |
elif action == "Generate Report":
|
270 |
path = generate_report(combined_text, report_fn)
|
|
|
1 |
import os
|
2 |
import io
|
3 |
import json
|
|
|
4 |
import asyncio
|
5 |
import xml.etree.ElementTree as ET
|
6 |
from typing import Any, Dict, Optional, Tuple, Union, List
|
|
|
149 |
})
|
150 |
return articles
|
151 |
|
152 |
+
def interpret_clinical_test_results(results: str) -> str:
|
153 |
+
"""Generate an expert-level clinical interpretation from raw results."""
|
154 |
try:
|
155 |
response = client.chat.completions.create(
|
156 |
model="gpt-3.5-turbo",
|
157 |
+
messages=[{"role": "user", "content": f"Interpret these clinical test results:\n{results}"}],
|
158 |
max_tokens=500,
|
159 |
temperature=0.7,
|
160 |
)
|
161 |
return response.choices[0].message.content.strip()
|
162 |
except Exception as e:
|
163 |
+
logger.error(f"Interpretation error: {e}")
|
164 |
+
return "Failed to interpret results."
|
165 |
|
166 |
###############################################################################
|
167 |
# 6) CORE FUNCTIONS #
|
|
|
175 |
response = client.chat.completions.create(
|
176 |
model="gpt-3.5-turbo",
|
177 |
messages=[{"role": "user", "content": f"Summarize this clinical data:\n{text}"}],
|
178 |
+
max_tokens=300,
|
179 |
temperature=0.7,
|
180 |
)
|
181 |
return response.choices[0].message.content.strip()
|
|
|
229 |
gr.Markdown("""
|
230 |
**Highlights**:
|
231 |
- **Summarize** clinical text (OpenAI GPT-3.5)
|
232 |
+
- **Interpret** clinical test results with expert-level insights
|
233 |
- **Generate** professional PDF reports
|
234 |
""")
|
235 |
|
|
|
237 |
action = gr.Radio(
|
238 |
[
|
239 |
"Summarize",
|
240 |
+
"Interpret Clinical Test Results",
|
241 |
"Generate Report",
|
242 |
],
|
243 |
label="Select an Action",
|
|
|
261 |
summary = summarize_text(combined_text)
|
262 |
return summary, None
|
263 |
|
264 |
+
elif action == "Interpret Clinical Test Results":
|
265 |
+
interpretation = interpret_clinical_test_results(combined_text)
|
266 |
+
return interpretation, None
|
267 |
|
268 |
elif action == "Generate Report":
|
269 |
path = generate_report(combined_text, report_fn)
|