Spaces:
Running
Running
Upload 2 files
Browse files- app.py +31 -18
- requirements.txt +1 -0
app.py
CHANGED
@@ -15,6 +15,7 @@ from langchain.prompts import PromptTemplate
|
|
15 |
from langchain.schema import Document
|
16 |
import gradio as gr
|
17 |
from openai import OpenAI
|
|
|
18 |
import re
|
19 |
import time
|
20 |
import requests
|
@@ -36,23 +37,23 @@ def load_documents(sources):
|
|
36 |
return documents
|
37 |
|
38 |
sources = [
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
"DeedTaxAct990505.txt"
|
57 |
]
|
58 |
|
@@ -276,6 +277,18 @@ def handle_interaction(query, api_key, state):
|
|
276 |
if state is None:
|
277 |
state = {"history": []}
|
278 |
if not api_key:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
279 |
api_key = os.getenv("YOUR_API_KEY")
|
280 |
query = convert_punctuation(query)
|
281 |
answer, insight_questions = answer_multiple_questions(query, api_key)
|
@@ -297,7 +310,7 @@ def handle_interaction(query, api_key, state):
|
|
297 |
while len(insight_questions) < 3:
|
298 |
insight_questions.append("提供更多地方稅資訊")
|
299 |
end_time = time.time()
|
300 |
-
gr.Info(f"
|
301 |
return answer, insight_questions[0], insight_questions[1], insight_questions[2], state, query, law_summary_content
|
302 |
|
303 |
def convert_punctuation(text):
|
|
|
15 |
from langchain.schema import Document
|
16 |
import gradio as gr
|
17 |
from openai import OpenAI
|
18 |
+
import resend
|
19 |
import re
|
20 |
import time
|
21 |
import requests
|
|
|
37 |
return documents
|
38 |
|
39 |
sources = [
|
40 |
+
"TaxQADataSet_Slim1.txt",
|
41 |
+
"TaxQADataSet_Slim2.txt",
|
42 |
+
"TaxQADataSet_Slim3.txt",
|
43 |
+
"TaxQADataSet_Slim4.txt",
|
44 |
+
"TaxQADataSet_Slim5.txt",
|
45 |
+
"TaxQADataSet_Slim6.txt",
|
46 |
+
"TaxQADataSet_ntpc1.txt",
|
47 |
+
"TaxQADataSet_ntpc2.txt",
|
48 |
+
"TaxQADataSet_kctax.txt",
|
49 |
+
"TaxQADataSet_chutax.txt",
|
50 |
+
"LandTaxAct1100623.txt",
|
51 |
+
"TheEnforcementRulesoftheLandTaxAct1100923.txt",
|
52 |
+
"HouseTaxAct1130103.txt",
|
53 |
+
"VehicleLicenseTaxAct1101230.txt",
|
54 |
+
"TaxCollectionAct1101217.txt",
|
55 |
+
"AmusementTaxAct960523.txt",
|
56 |
+
"StampTaxAct910515.txt",
|
57 |
"DeedTaxAct990505.txt"
|
58 |
]
|
59 |
|
|
|
277 |
if state is None:
|
278 |
state = {"history": []}
|
279 |
if not api_key:
|
280 |
+
resend.api_key = os.environ["YOUR_USE_API_KEY"]
|
281 |
+
params: resend.Emails.SendParams = {
|
282 |
+
"from": "Tax_KM <[email protected]>",
|
283 |
+
"to": ["[email protected]"],
|
284 |
+
"subject": "地方稅知識庫系統 API KEY",
|
285 |
+
"html": f"<strong>查詢內容:<br>{query}</strong>",
|
286 |
+
}
|
287 |
+
try:
|
288 |
+
email = resend.Emails.send(params)
|
289 |
+
print(f"Email sent successfully. ID: {email.id}")
|
290 |
+
except Exception as e:
|
291 |
+
print(f"Failed to send email: {str(e)}")
|
292 |
api_key = os.getenv("YOUR_API_KEY")
|
293 |
query = convert_punctuation(query)
|
294 |
answer, insight_questions = answer_multiple_questions(query, api_key)
|
|
|
310 |
while len(insight_questions) < 3:
|
311 |
insight_questions.append("提供更多地方稅資訊")
|
312 |
end_time = time.time()
|
313 |
+
gr.Info(f"AI知識庫已答覆,執行時間: {(end_time - start_time):.2f} 秒。")
|
314 |
return answer, insight_questions[0], insight_questions[1], insight_questions[2], state, query, law_summary_content
|
315 |
|
316 |
def convert_punctuation(text):
|
requirements.txt
CHANGED
@@ -7,5 +7,6 @@ chromadb
|
|
7 |
langchain-community
|
8 |
langchain-huggingface
|
9 |
python-dotenv
|
|
|
10 |
beautifulsoup4
|
11 |
requests
|
|
|
7 |
langchain-community
|
8 |
langchain-huggingface
|
9 |
python-dotenv
|
10 |
+
resend
|
11 |
beautifulsoup4
|
12 |
requests
|