From 79fb0e781b9c459cfc5bbe7dd59283aec175e4e2 Mon Sep 17 00:00:00 2001 From: Prayas Jain <pjain03@safeway.com> Date: Sat, 18 Jan 2025 13:53:32 +0530 Subject: [PATCH] Intgegrate api with submit button --- src/api.py | 13 +++++++++++++ src/dashboard.py | 23 ++++++++++++++++++----- src/requirements.txt | 4 +++- 3 files changed, 34 insertions(+), 6 deletions(-) diff --git a/src/api.py b/src/api.py index fe2411c..52cc93f 100644 --- a/src/api.py +++ b/src/api.py @@ -1,9 +1,22 @@ from fastapi import APIRouter, HTTPException from fastapi.responses import FileResponse +from pydantic import BaseModel import os router = APIRouter() +# Define a Pydantic model for the data we expect in the POST request +class InputData(BaseModel): + jobTitle: str + department: str + jobDescription: str + +# POST endpoint +@router.post("/submit/") +async def submit_data(data: InputData): + # Here, you can process the data (e.g., save it to a database) + return {"message": "Data received successfully!", "data": data.dict()} + @router.get("/read-file") async def read_file(file_path: str): # Define the base directory for public files diff --git a/src/dashboard.py b/src/dashboard.py index a21bafc..22a49d5 100644 --- a/src/dashboard.py +++ b/src/dashboard.py @@ -1,4 +1,8 @@ import streamlit as st +import requests + +# FastAPI URL (assuming it is running locally on port 8000) +API_URL = "http://127.0.0.1:8000/submit/" # Title of the app st.title("Enter JD to fetch resumes!") @@ -11,9 +15,18 @@ job_description = st.text_area("Job Description", height=200) # Add a submit button if st.button("Submit"): if job_title and department and job_description: - st.success("Job Description Submitted Successfully!") - st.write(f"**Job Title:** {job_title}") - st.write(f"**Department:** {department}") - st.write(f"**Job Description:** {job_description}") + data = { + "jobTitle": job_title, + "department": department, + "jobDescription": job_description + } + response = requests.post(API_URL, json=data) + # If the request is successful, display the response + if response.status_code == 200: + result = response.json() + st.success(result['message']) + st.write("Received Data:", result['data']) + else: + st.error(f"Error: {response.status_code}") else: - st.error("Please fill in all the fields.") \ No newline at end of file + st.warning("Please fill in all the fields!") \ No newline at end of file diff --git a/src/requirements.txt b/src/requirements.txt index 5836f13..d9954d2 100644 --- a/src/requirements.txt +++ b/src/requirements.txt @@ -4,4 +4,6 @@ scikit-learn transformers streamlit fastapi - +uvicorn +requests +router \ No newline at end of file -- 2.18.1