Solar-Iz commited on
Commit
632b74a
·
1 Parent(s): bb46aec

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -10
app.py CHANGED
@@ -1,11 +1,20 @@
1
- import streamlit as st
2
  import requests
 
3
  import json
4
 
5
  def main():
6
 
7
  st.title("FastAPI - Streamlit Integration")
8
 
 
 
 
 
 
 
 
 
 
9
  # Эндпоинт для классификации текста
10
  text_input = st.text_input("Enter text for classification:")
11
  if st.button("Classify Text"):
@@ -13,14 +22,5 @@ def main():
13
  result = response.json()
14
  st.success(f"Classification result: {result['prediction']}")
15
 
16
- # Эндпоинт для классификации изображений
17
- image_path = st.file_uploader("Upload an image for classification:", type=["jpg", "png"])
18
- if image_path is not None:
19
- if st.button("Classify Image"):
20
- files = {"file": image_path.read()}
21
- response = requests.post("http://127.0.0.1:8000/classify", files=files)
22
- result = response.json()
23
- st.success(f"Classification result: {result['prediction']}")
24
-
25
  if __name__ == '__main__':
26
  main()
 
 
1
  import requests
2
+ import streamlit as st
3
  import json
4
 
5
  def main():
6
 
7
  st.title("FastAPI - Streamlit Integration")
8
 
9
+ image = st.file_uploader("Choose an image", type=['jpg', 'jpeg'])
10
+
11
+ if st.button("Classify!"):
12
+ if image is not None:
13
+ st.image(image)
14
+ files = {"file": image.getvalue()}
15
+ res = requests.post("http://127.0.0.1:8000/classify", files=files)
16
+ st.write(json.loads(res.text)['prediction'])
17
+
18
  # Эндпоинт для классификации текста
19
  text_input = st.text_input("Enter text for classification:")
20
  if st.button("Classify Text"):
 
22
  result = response.json()
23
  st.success(f"Classification result: {result['prediction']}")
24
 
 
 
 
 
 
 
 
 
 
25
  if __name__ == '__main__':
26
  main()