| import requests |
| import streamlit as st |
| import json |
|
|
| def main(): |
|
|
| st.title("FastAPI - Streamlit Integration") |
|
|
| image = st.file_uploader("Choose an image", type=['jpg', 'jpeg']) |
|
|
| if st.button("Classify!"): |
| if image is not None: |
| st.image(image) |
| files = {"file": image.getvalue()} |
| res = requests.post("http://127.0.0.1:8000/classify", files=files) |
| st.write(json.loads(res.text)['prediction']) |
|
|
| |
| text_input = st.text_input("Enter text for classification:") |
| if st.button("Classify Text"): |
| response = requests.post("http://127.0.0.1:8000/clf_text", json={"text": text_input}) |
| result = response.json() |
| st.success(f"Classification result: {result['prediction']}") |
|
|
| if __name__ == '__main__': |
| main() |