-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
67 lines (49 loc) · 1.88 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import streamlit as st
import pandas as pd
import numpy as np
from langchain_community.vectorstores import Milvus
from langchain_openai import OpenAIEmbeddings
import dspy
import re
import streamlit_scrollable_textbox as stx
from summarizer import Summarizer
#### DSPy
ollama_model = dspy.OllamaLocal(model='llama3',model_type='chat')
dspy.settings.configure(lm=ollama_model)
class Summarizer(dspy.Signature):
"""Document summarifying based on llama-3 and DSPy"""
document = dspy.InputField(desc="A legal opinion document, a written explanation by a judge that accompanies an order or ruling in a case")
summary = dspy.OutputField(desc="Summarization of legal opinion document")
summarize = dspy.Predict(Summarizer)
## STREAMLIT + MILVUS
st.title('Vector Search over Legal Database')
embeddings = OpenAIEmbeddings(model = "text-embedding-3-large")
vector_db = Milvus(
embeddings,
connection_args={"host": "127.0.0.1", "port": "19530"},
collection_name="LangChainCollection",
)
instr = 'Ignite ideas..!🔥'
with st.form('chat_input_form'):
# Create two columns; adjust the ratio to your liking
col1, col2 = st.columns([3,1])
# Use the first column for text input
with col1:
prompt = st.text_input(
instr,
value=instr,
placeholder=instr,
label_visibility='collapsed'
)
# Use the second column for the submit button
with col2:
submitted = st.form_submit_button('🔍')
if prompt and submitted:
result = vector_db.similarity_search(prompt)
response = summarize(document = result[0].page_content)
st.write("TLDR: ", response.summary)
st.write(result[0].page_content)
st.write(result[0].metadata)
print(response.summary)
#stx.scrollableTextbox(result[1].page_content)
#st.write("source: ", result[1].metadata, )