Spaces:
Running
Running
up
Browse files
app.py
CHANGED
@@ -6,7 +6,7 @@ import docx2txt
|
|
6 |
from sklearn.feature_extraction.text import TfidfVectorizer
|
7 |
from sklearn.metrics.pairwise import cosine_similarity
|
8 |
import difflib
|
9 |
-
from huggingface_hub import
|
10 |
|
11 |
# ========== CONFIG ==========
|
12 |
st.set_page_config(page_title="📑 Contract Analyzer", layout="wide")
|
@@ -15,10 +15,10 @@ st.set_page_config(page_title="📑 Contract Analyzer", layout="wide")
|
|
15 |
|
16 |
# Tải mô hình Hugging Face từ Hub
|
17 |
@st.cache_resource
|
18 |
-
def
|
19 |
-
return
|
20 |
|
21 |
-
|
22 |
|
23 |
def extract_text_from_pdf(uploaded_file):
|
24 |
try:
|
@@ -78,7 +78,7 @@ def compute_similarity(text1, text2):
|
|
78 |
def query_zephyr_model(text1, text2, question):
|
79 |
prompt = f"Compare the following two contracts and answer the question:\nText 1: {text1}\nText 2: {text2}\nQuestion: {question}"
|
80 |
try:
|
81 |
-
result =
|
82 |
return result['generated_text']
|
83 |
except Exception as e:
|
84 |
st.error(f"Error querying the model: {e}")
|
@@ -129,24 +129,16 @@ def main():
|
|
129 |
user_question = st.text_input("Enter your question about the contracts:")
|
130 |
|
131 |
if user_question and st.button("Analyze Question"):
|
132 |
-
|
133 |
-
with col1:
|
134 |
-
st.subheader("Answer from Document 1")
|
135 |
-
with st.spinner("Analyzing..."):
|
136 |
-
try:
|
137 |
-
pred1 = query_zephyr_model(text1, text2, user_question)
|
138 |
-
st.success(pred1)
|
139 |
-
except Exception as e:
|
140 |
-
st.error(f"Failed on Document 1: {e}")
|
141 |
|
142 |
-
with
|
143 |
-
st.subheader("Answer from Document
|
144 |
with st.spinner("Analyzing..."):
|
145 |
try:
|
146 |
-
|
147 |
-
st.success(
|
148 |
except Exception as e:
|
149 |
-
st.error(f"Failed on Document
|
150 |
|
151 |
if __name__ == "__main__":
|
152 |
main()
|
|
|
6 |
from sklearn.feature_extraction.text import TfidfVectorizer
|
7 |
from sklearn.metrics.pairwise import cosine_similarity
|
8 |
import difflib
|
9 |
+
from huggingface_hub import InferenceClient # Import Hugging Face API
|
10 |
|
11 |
# ========== CONFIG ==========
|
12 |
st.set_page_config(page_title="📑 Contract Analyzer", layout="wide")
|
|
|
15 |
|
16 |
# Tải mô hình Hugging Face từ Hub
|
17 |
@st.cache_resource
|
18 |
+
def load_inference_client():
|
19 |
+
return InferenceClient(repo_id="HuggingFaceH4/zephyr-7b-beta") # Mô hình Zephyr
|
20 |
|
21 |
+
inference_client = load_inference_client()
|
22 |
|
23 |
def extract_text_from_pdf(uploaded_file):
|
24 |
try:
|
|
|
78 |
def query_zephyr_model(text1, text2, question):
|
79 |
prompt = f"Compare the following two contracts and answer the question:\nText 1: {text1}\nText 2: {text2}\nQuestion: {question}"
|
80 |
try:
|
81 |
+
result = inference_client(inputs=prompt)
|
82 |
return result['generated_text']
|
83 |
except Exception as e:
|
84 |
st.error(f"Error querying the model: {e}")
|
|
|
129 |
user_question = st.text_input("Enter your question about the contracts:")
|
130 |
|
131 |
if user_question and st.button("Analyze Question"):
|
132 |
+
col = st.columns(1)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
133 |
|
134 |
+
with col:
|
135 |
+
st.subheader("Answer from Document")
|
136 |
with st.spinner("Analyzing..."):
|
137 |
try:
|
138 |
+
pred = query_zephyr_model(text1, text2, user_question)
|
139 |
+
st.success(pred)
|
140 |
except Exception as e:
|
141 |
+
st.error(f"Failed on Document: {e}")
|
142 |
|
143 |
if __name__ == "__main__":
|
144 |
main()
|