J4Lee commited on
Commit
d11c821
1 Parent(s): b26390c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -8
app.py CHANGED
@@ -10,9 +10,9 @@ st.set_page_config(page_title="RadiantScriptor")
10
  def query_huggingface_model(data):
11
  API_TOKEN = "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"
12
  API_URL = "https://poxj7ux0l7kszkjs.us-east-1.aws.endpoints.huggingface.cloud"
13
-
14
  headers = {"Authorization": f"Bearer {API_TOKEN}"}
15
- response = requests.post(API_URL, headers=headers, json={"inputs": data})
16
 
17
  if response.status_code == 200:
18
  return response.json()
@@ -20,27 +20,28 @@ def query_huggingface_model(data):
20
  return {"error": response.text}
21
 
22
  # Streamlit interface
 
 
23
  st.title("Radiology Report Generator")
24
 
25
  # User input for uploading a text file
26
  uploaded_file = st.file_uploader("Upload a text file", type=["txt"])
27
- labels = ""
28
 
29
  if uploaded_file is not None:
30
  # Read the contents of the uploaded text file
31
- labels = uploaded_file.read().decode("utf-8")
32
  # Display the content to the user (optional)
33
- st.text_area("File content:", value=labels, height=150)
34
 
35
  if st.button("Generate Report"):
36
  with st.spinner('Generating report...'):
37
  # Query the Hugging Face model API
38
- response = query_huggingface_model(labels)
39
  if "error" in response:
40
  st.error(f"Error: {response['error']}")
41
  else:
42
  # Assuming the response is a JSON object containing the generated text
43
- report = response[0]
44
  # Display the report
45
  st.text_area("Generated Report:", value=report, height=300)
46
-
 
10
  def query_huggingface_model(data):
11
  API_TOKEN = "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"
12
  API_URL = "https://poxj7ux0l7kszkjs.us-east-1.aws.endpoints.huggingface.cloud"
13
+
14
  headers = {"Authorization": f"Bearer {API_TOKEN}"}
15
+ response = requests.post(API_URL, headers=headers, json={"inputs": prompt})
16
 
17
  if response.status_code == 200:
18
  return response.json()
 
20
  return {"error": response.text}
21
 
22
  # Streamlit interface
23
+ st.set_page_config(page_title="Radiology Report Generator")
24
+
25
  st.title("Radiology Report Generator")
26
 
27
  # User input for uploading a text file
28
  uploaded_file = st.file_uploader("Upload a text file", type=["txt"])
29
+ user_prompt = ""
30
 
31
  if uploaded_file is not None:
32
  # Read the contents of the uploaded text file
33
+ user_prompt = uploaded_file.read().decode("utf-8")
34
  # Display the content to the user (optional)
35
+ st.text_area("Uploaded Text:", value=user_prompt, height=150)
36
 
37
  if st.button("Generate Report"):
38
  with st.spinner('Generating report...'):
39
  # Query the Hugging Face model API
40
+ response = query_huggingface_model(user_prompt)
41
  if "error" in response:
42
  st.error(f"Error: {response['error']}")
43
  else:
44
  # Assuming the response is a JSON object containing the generated text
45
+ report = response[0]['generated_text'] # Adjust based on the actual response structure
46
  # Display the report
47
  st.text_area("Generated Report:", value=report, height=300)