add app and the response structure
Browse files- app.py +63 -0
- responses.py +16 -0
app.py
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import requests
|
| 2 |
+
import streamlit as st
|
| 3 |
+
|
| 4 |
+
from responses import SubmitQuestionAndDocumentsResponse
|
| 5 |
+
|
| 6 |
+
st.set_page_config(layout="wide")
|
| 7 |
+
|
| 8 |
+
def make_sidebar():
|
| 9 |
+
with st.sidebar:
|
| 10 |
+
st.title("Sidebar")
|
| 11 |
+
st.write("This is a sidebar.")
|
| 12 |
+
st.write("You can add widgets here")
|
| 13 |
+
|
| 14 |
+
def create_payload(question, logs):
|
| 15 |
+
payload = {
|
| 16 |
+
"question": question,
|
| 17 |
+
"logs": logs
|
| 18 |
+
}
|
| 19 |
+
# st.write(payload)
|
| 20 |
+
return payload
|
| 21 |
+
|
| 22 |
+
def process_payload(payload):
|
| 23 |
+
all_logs = payload["logs"]
|
| 24 |
+
text = ""
|
| 25 |
+
for log in all_logs:
|
| 26 |
+
text += requests.get(log).text
|
| 27 |
+
|
| 28 |
+
payload['text'] = text
|
| 29 |
+
return payload
|
| 30 |
+
|
| 31 |
+
def main():
|
| 32 |
+
st.title("Hello, World!")
|
| 33 |
+
# print("Hello, World!")
|
| 34 |
+
make_sidebar()
|
| 35 |
+
|
| 36 |
+
col1, col2 = st.columns(2)
|
| 37 |
+
|
| 38 |
+
with col1:
|
| 39 |
+
st.write("This is column 2")
|
| 40 |
+
logs = st.multiselect("Select the options",
|
| 41 |
+
[
|
| 42 |
+
"https://storage.googleapis.com/cleric-assignment-call-logs/call_log_20240314_104111.txt",
|
| 43 |
+
"https://storage.googleapis.com/cleric-assignment-call-logs/call_log_20240315_104111.txt",
|
| 44 |
+
"https://storage.googleapis.com/cleric-assignment-call-logs/call_log_20240316_104111.txt",])
|
| 45 |
+
|
| 46 |
+
with col2:
|
| 47 |
+
st.write("This is column 1")
|
| 48 |
+
question = st.text_input("Ask the question", value="What product design decisions did the team make?")
|
| 49 |
+
|
| 50 |
+
payload = create_payload(question, logs)
|
| 51 |
+
processed_payload = process_payload(payload)
|
| 52 |
+
# st.write(processed_payload)
|
| 53 |
+
|
| 54 |
+
data = SubmitQuestionAndDocumentsResponse(**processed_payload)
|
| 55 |
+
st.write(data.model_dump())
|
| 56 |
+
|
| 57 |
+
if st.button("Submit"):
|
| 58 |
+
resp = requests.post("http://127.0.0.1:8000/submit_question_and_documents", json=data.model_dump())
|
| 59 |
+
st.write(resp.status_code)
|
| 60 |
+
st.write(resp.json())
|
| 61 |
+
|
| 62 |
+
if __name__ == "__main__":
|
| 63 |
+
main()
|
responses.py
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
from typing import List, Optional
|
| 3 |
+
|
| 4 |
+
from pydantic import BaseModel
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
class GetQuestionAndFactsResponse(BaseModel):
|
| 8 |
+
question: str
|
| 9 |
+
facts: Optional[List[str]]
|
| 10 |
+
status: str
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
class SubmitQuestionAndDocumentsResponse(BaseModel):
|
| 14 |
+
question: str
|
| 15 |
+
logs: List[str]
|
| 16 |
+
text: str
|