Spaces:
Sleeping
Sleeping
Commit
·
fa07efb
1
Parent(s):
5c0ba2e
update to pii extraction
Browse files- app.py +25 -183
- openai_gradio_20250314_dynamic 1.ipynb +0 -228
- requirements.txt +0 -1
app.py
CHANGED
|
@@ -1,193 +1,35 @@
|
|
| 1 |
-
# import gradio as gr
|
| 2 |
-
# from huggingface_hub import InferenceClient
|
| 3 |
-
|
| 4 |
-
# """
|
| 5 |
-
# For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
|
| 6 |
-
# """
|
| 7 |
-
# client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
# def respond(
|
| 11 |
-
# message,
|
| 12 |
-
# history: list[tuple[str, str]],
|
| 13 |
-
# system_message,
|
| 14 |
-
# max_tokens,
|
| 15 |
-
# temperature,
|
| 16 |
-
# top_p,
|
| 17 |
-
# ):
|
| 18 |
-
# messages = [{"role": "system", "content": system_message}]
|
| 19 |
-
|
| 20 |
-
# for val in history:
|
| 21 |
-
# if val[0]:
|
| 22 |
-
# messages.append({"role": "user", "content": val[0]})
|
| 23 |
-
# if val[1]:
|
| 24 |
-
# messages.append({"role": "assistant", "content": val[1]})
|
| 25 |
-
|
| 26 |
-
# messages.append({"role": "user", "content": message})
|
| 27 |
-
|
| 28 |
-
# response = ""
|
| 29 |
-
|
| 30 |
-
# for message in client.chat_completion(
|
| 31 |
-
# messages,
|
| 32 |
-
# max_tokens=max_tokens,
|
| 33 |
-
# stream=True,
|
| 34 |
-
# temperature=temperature,
|
| 35 |
-
# top_p=top_p,
|
| 36 |
-
# ):
|
| 37 |
-
# token = message.choices[0].delta.content
|
| 38 |
-
|
| 39 |
-
# response += token
|
| 40 |
-
# yield response
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
# """
|
| 44 |
-
# For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
|
| 45 |
-
# """
|
| 46 |
-
# demo = gr.ChatInterface(
|
| 47 |
-
# respond,
|
| 48 |
-
# additional_inputs=[
|
| 49 |
-
# gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
|
| 50 |
-
# gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
|
| 51 |
-
# gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
|
| 52 |
-
# gr.Slider(
|
| 53 |
-
# minimum=0.1,
|
| 54 |
-
# maximum=1.0,
|
| 55 |
-
# value=0.95,
|
| 56 |
-
# step=0.05,
|
| 57 |
-
# label="Top-p (nucleus sampling)",
|
| 58 |
-
# ),
|
| 59 |
-
# ],
|
| 60 |
-
# )
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
# if __name__ == "__main__":
|
| 64 |
-
# demo.launch()
|
| 65 |
-
|
| 66 |
-
|
| 67 |
import gradio as gr
|
| 68 |
import requests
|
| 69 |
-
import re
|
| 70 |
|
| 71 |
-
# endpoint :
|
| 72 |
-
deployment_name = "fimtrus-gpt-4o-ncus"
|
| 73 |
-
endpoint = "https://fimtrus-openai-ncus.openai.azure.com/openai/deployments/{}/chat/completions".format(deployment_name)
|
| 74 |
-
api_key = "FP7k76c0BGmz4MVot1LVqdtqcmQaKBeerYdFyXzW4NXN0940rRfEJQQJ99BCACHrzpqXJ3w3AAABACOG8189"
|
| 75 |
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
"endpoint": ai_search_endpoint,
|
| 97 |
-
"index_name": ai_search_index_name,
|
| 98 |
-
"semantic_configuration": ai_search_semantic,
|
| 99 |
-
"query_type": "semantic",
|
| 100 |
-
"fields_mapping": {},
|
| 101 |
-
"in_scope": True,
|
| 102 |
-
"filter": None,
|
| 103 |
-
"strictness": 3,
|
| 104 |
-
"top_n_documents": 3,
|
| 105 |
-
"authentication": {
|
| 106 |
-
"type": "api_key",
|
| 107 |
-
"key": ai_search_key
|
| 108 |
},
|
| 109 |
-
"key": ai_search_key
|
| 110 |
-
}
|
| 111 |
-
}
|
| 112 |
-
],
|
| 113 |
-
"messages": [
|
| 114 |
-
{
|
| 115 |
-
"role": "system",
|
| 116 |
-
"content": "사용자가 정보를 찾는 데 도움이 되는 AI 도우미입니다."
|
| 117 |
},
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
}
|
| 122 |
-
],
|
| 123 |
-
"temperature": 0.7,
|
| 124 |
-
"top_p": 0.95,
|
| 125 |
-
"max_tokens": 800,
|
| 126 |
-
"stop": None,
|
| 127 |
-
"stream": False,
|
| 128 |
-
"frequency_penalty": 0,
|
| 129 |
-
"presence_penalty": 0
|
| 130 |
-
}
|
| 131 |
-
|
| 132 |
-
response = requests.post(endpoint, params=query_params, headers=headers, json=body)
|
| 133 |
-
|
| 134 |
-
if response.status_code == 200:
|
| 135 |
-
response_json = response.json()
|
| 136 |
-
message = response_json['choices'][0]['message']
|
| 137 |
-
content = message['content']
|
| 138 |
-
|
| 139 |
-
content = re.sub(r'\[doc(\d+)\]', r'[참조 \1]', content)
|
| 140 |
-
|
| 141 |
-
if message['context']:
|
| 142 |
-
citation_list = message['context']['citations']
|
| 143 |
-
else:
|
| 144 |
-
citation_list = list()
|
| 145 |
-
return content, citation_list
|
| 146 |
-
else:
|
| 147 |
-
return "", list()
|
| 148 |
-
|
| 149 |
-
with gr.Blocks(css=".gradio-container {background-color: #e5e5f7;opacity: 0.8;background-image: radial-gradient(circle at center center, #444cf7, #e5e5f7), repeating-radial-gradient(circle at center center, #444cf7, #444cf7, 10px, transparent 20px, transparent 10px);background-blend-mode: multiply;}") as demo:
|
| 150 |
-
|
| 151 |
-
citation_state = gr.State([])
|
| 152 |
-
|
| 153 |
-
def click_send(prompt, histories):
|
| 154 |
-
print(prompt)
|
| 155 |
-
content, citation_list = request_gpt(prompt=prompt)
|
| 156 |
-
message_list = [{"role": "user", "content": prompt}, {"role": "assistant", "content": content}]
|
| 157 |
-
histories.extend(message_list)
|
| 158 |
-
|
| 159 |
-
print(histories)
|
| 160 |
-
print(len(citation_list), citation_list)
|
| 161 |
-
return histories, citation_list, ""
|
| 162 |
-
|
| 163 |
-
def select_tab(citation):
|
| 164 |
-
print("tab!!!!!!")
|
| 165 |
-
return gr.Textbox(label="", value=citation, lines=10, max_lines=10, visible=True)
|
| 166 |
-
|
| 167 |
-
gr.Markdown("# 남해 맛집 말고는 안 알려줄거여 👅")
|
| 168 |
-
|
| 169 |
-
with gr.Row():
|
| 170 |
-
chatbot = gr.Chatbot(label="무러보시게", type="messages", scale=3)
|
| 171 |
-
|
| 172 |
-
with gr.Column(scale=1):
|
| 173 |
-
@gr.render(inputs=[citation_state])
|
| 174 |
-
def render_citations(citations):
|
| 175 |
-
print(citations)
|
| 176 |
-
for index in range(len(citations)):
|
| 177 |
-
content = citations[index]['content']
|
| 178 |
-
key = "참조{}".format(index + 1)
|
| 179 |
-
if index == 0:
|
| 180 |
-
gr.Tab("", id=-1, visible=False)
|
| 181 |
-
with gr.Tab(key) as tab:
|
| 182 |
-
citation_textbox = gr.Textbox(label="", value=content, lines=10, max_lines=10, visible=False)
|
| 183 |
-
tab.select(fn=select_tab, inputs=[citation_textbox], outputs=[citation_textbox])
|
| 184 |
|
| 185 |
-
with gr.Row():
|
| 186 |
-
prompt_textbox = gr.Textbox(label="질문", placeholder="질문을 입력하세요.", scale=6)
|
| 187 |
-
send_button = gr.Button("전송", scale=1)
|
| 188 |
|
| 189 |
-
|
| 190 |
-
prompt_textbox.submit(click_send, inputs=[prompt_textbox, chatbot], outputs=[chatbot, citation_state, prompt_textbox])
|
| 191 |
|
| 192 |
if __name__ == "__main__":
|
| 193 |
-
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import requests
|
|
|
|
| 3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
+
def extract_pii(text):
|
| 6 |
+
res = requests.post(
|
| 7 |
+
"https://6b044.cognitiveservices.azure.com/language/:analyze-text?api-version=2022-05-01",
|
| 8 |
+
headers={
|
| 9 |
+
"Ocp-Apim-Subscription-Key": "941b608ce2634805b169eca63f51b856",
|
| 10 |
+
"Content-Type": "application/json",
|
| 11 |
+
},
|
| 12 |
+
json={
|
| 13 |
+
"kind": "PiiEntityRecognition",
|
| 14 |
+
"parameters": {
|
| 15 |
+
"modelVersion": "latest",
|
| 16 |
+
},
|
| 17 |
+
"analysisInput":{
|
| 18 |
+
"documents":[
|
| 19 |
+
{
|
| 20 |
+
"id":"1",
|
| 21 |
+
"language": "en",
|
| 22 |
+
"text": text,
|
| 23 |
+
},
|
| 24 |
+
],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
},
|
| 27 |
+
)
|
| 28 |
+
pii_entities = res.json()["results"]["documents"][0]["entities"]
|
| 29 |
+
return str(pii_entities)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
|
|
|
|
|
|
|
|
|
|
| 31 |
|
| 32 |
+
demo = gr.Interface(fn=extract_pii, inputs="textbox", outputs="textbox")
|
|
|
|
| 33 |
|
| 34 |
if __name__ == "__main__":
|
| 35 |
+
demo.launch()
|
openai_gradio_20250314_dynamic 1.ipynb
DELETED
|
@@ -1,228 +0,0 @@
|
|
| 1 |
-
{
|
| 2 |
-
"cells": [
|
| 3 |
-
{
|
| 4 |
-
"cell_type": "code",
|
| 5 |
-
"execution_count": null,
|
| 6 |
-
"metadata": {},
|
| 7 |
-
"outputs": [
|
| 8 |
-
{
|
| 9 |
-
"name": "stdout",
|
| 10 |
-
"output_type": "stream",
|
| 11 |
-
"text": [
|
| 12 |
-
"* Running on local URL: http://127.0.0.1:7870\n",
|
| 13 |
-
"\n",
|
| 14 |
-
"To create a public link, set `share=True` in `launch()`.\n"
|
| 15 |
-
]
|
| 16 |
-
},
|
| 17 |
-
{
|
| 18 |
-
"data": {
|
| 19 |
-
"text/html": [
|
| 20 |
-
"<div><iframe src=\"http://127.0.0.1:7870/\" width=\"100%\" height=\"500\" allow=\"autoplay; camera; microphone; clipboard-read; clipboard-write;\" frameborder=\"0\" allowfullscreen></iframe></div>"
|
| 21 |
-
],
|
| 22 |
-
"text/plain": [
|
| 23 |
-
"<IPython.core.display.HTML object>"
|
| 24 |
-
]
|
| 25 |
-
},
|
| 26 |
-
"metadata": {},
|
| 27 |
-
"output_type": "display_data"
|
| 28 |
-
},
|
| 29 |
-
{
|
| 30 |
-
"data": {
|
| 31 |
-
"text/plain": []
|
| 32 |
-
},
|
| 33 |
-
"execution_count": 11,
|
| 34 |
-
"metadata": {},
|
| 35 |
-
"output_type": "execute_result"
|
| 36 |
-
},
|
| 37 |
-
{
|
| 38 |
-
"name": "stdout",
|
| 39 |
-
"output_type": "stream",
|
| 40 |
-
"text": [
|
| 41 |
-
"[]\n",
|
| 42 |
-
"서면 갈만한곳\n",
|
| 43 |
-
"[{'role': 'user', 'content': '서면 갈만한곳'}, {'role': 'assistant', 'content': '경상남도 남해군 서면에서 갈만한 곳은 다음과 같습니다:\\n\\n1. **스포츠파크**: 이곳은 남해군의 대표적인 축구 훈련장으로, 계절에 관계없이 사용 가능한 시설입니다. 전국 각지의 전지훈련객들이 많이 찾는 곳입니다 [참조 1].\\n - 위치: 경상남도 남해군 서면 스포츠파크길 74\\n - 전화번호: 055-860-8661\\n\\n2. **장항거리**: 이곳은 사계절 내내 가족 단위 관광객들이 즐기기 좋은 장소입니다 [참조 2].\\n - 위치: 경상남도 남해군 서면 남서대로1517번길 31\\n\\n3. **망운산 철쭉군락지**: 5월에 철쭉이 만개하는 이곳은 많은 사람들이 찾는 명소입니다. 정상까지는 약 1시간 30분 정도 소요됩니다 [참조 3].\\n - 위치: 경상남도 남해군 서면 노구리 산 786m\\n - 전화번호: 055-860-3676'}]\n",
|
| 44 |
-
"3 [{'content': '경상남도 남해군 서면 스포츠파크길 74\\n2002년 월드컵이 유치되면서 남해의 축구열기가 고조되었다. 많은 이들의 수요을 충족하기 위해 조성된 남해의 잔디 구장은 계절에 관계없이 사용할 수 있어 전국각지의 전지훈련객들에게 사랑받고 있다. 산책로가 조성되어 있어 산책하기도 안성맞춤이다.\\nY\\n34.8054935\\n127.8337739\\n스포츠파크\\n055-860-8661\\n봄, 여름, 가을, 겨울, 자가용/렌트, 친구, 키즈, 연인, 우정女, 우정男, 효도, 나홀로, 단체\\n관광지', 'title': None, 'url': None, 'filepath': None, 'chunk_id': '0'}, {'content': '경상남도 남해군 서면 남서대로1517번길 31\\nN\\n34.8004847\\n127.8364069\\n장항거리\\n봄, 여름, 가을, 겨울, 자가용/렌트, 친구, 키즈, 연인, 우정女, 우정男, 효도, 나홀로\\n관광지', 'title': None, 'url': None, 'filepath': None, 'chunk_id': '0'}, {'content': '경상남도 남해군 서면 노구리 산98\\n786m, 남해 최고 높이를 자랑하는 망운산. 5월에는 철쭉군락지의 꽃들이 만개해 가족단위나 친목회 등의 모임에서 많이 찾아오며, 정상까지는 1시간 30분정도 소요된다. 남해읍에서 관광안내판을 따라 남해대교 방향으로 3분 정도 가면 고현면 이어마을이 나타난다.\\nY\\n34.8569462\\n127.8514638\\n망운산 철쭉군락지\\n10\\n055-860-3676\\n봄, 자가용/렌트, 버스, 우정男, 나홀로, 단체\\n관광지', 'title': None, 'url': None, 'filepath': None, 'chunk_id': '0'}]\n",
|
| 45 |
-
"[{'content': '경상남도 남해군 서면 스포츠파크길 74\\n2002년 월드컵이 유치되면서 남해의 축구열기가 고조되었다. 많은 이들의 수요을 충족하기 위해 조성된 남해의 잔디 구장은 계절에 관계없이 사용할 수 있어 전국각지의 전지훈련객들에게 사랑받고 있다. 산책로가 조성되어 있어 산책하기도 안성맞춤이다.\\nY\\n34.8054935\\n127.8337739\\n스포츠파크\\n055-860-8661\\n봄, 여름, 가을, 겨울, 자가용/렌트, 친구, 키즈, 연인, 우정女, 우정男, 효도, 나홀로, 단체\\n관광지', 'title': None, 'url': None, 'filepath': None, 'chunk_id': '0'}, {'content': '경상남도 남해군 서면 남서대로1517번길 31\\nN\\n34.8004847\\n127.8364069\\n장항거리\\n봄, 여름, 가을, 겨울, 자가용/렌트, 친구, 키즈, 연인, 우정女, 우정男, 효도, 나홀로\\n관광지', 'title': None, 'url': None, 'filepath': None, 'chunk_id': '0'}, {'content': '경상남도 남해군 서면 노구리 산98\\n786m, 남해 최고 높이를 자랑하는 망운산. 5월에는 철쭉군락지의 꽃들이 만개해 가족단위나 친목회 등의 모임에서 많이 찾아오며, 정상까지는 1시간 30분정도 소요된다. 남해읍에서 관광안내판을 따라 남해대교 방향으로 3분 정도 가면 고현면 이어마을이 나타난다.\\nY\\n34.8569462\\n127.8514638\\n망운산 철쭉군락지\\n10\\n055-860-3676\\n봄, 자가용/렌트, 버스, 우정男, 나홀로, 단체\\n관광지', 'title': None, 'url': None, 'filepath': None, 'chunk_id': '0'}]\n",
|
| 46 |
-
"남해읍 갈만한곳\n",
|
| 47 |
-
"[{'role': 'user', 'metadata': {'title': None}, 'content': '서면 갈만한곳', 'options': None}, {'role': 'assistant', 'metadata': {'title': None}, 'content': '경상남도 남해군 서면에서 갈만한 곳은 다음과 같습니다:\\n\\n1. **스포츠파크**: 이곳은 남해군의 대표적인 축구 훈련장으로, 계절에 관계없이 사용 가능한 시설입니다. 전국 각지의 전지훈련객들이 많이 찾는 곳입니다 [참조 1].\\n - 위치: 경상남도 남해군 서면 스포츠파크길 74\\n - 전화번호: 055-860-8661\\n\\n2. **장항거리**: 이곳은 사계절 내내 가족 단위 관광객들이 즐기기 좋은 장소입니다 [참조 2].\\n - 위치: 경상남도 남해군 서면 남서대로1517번길 31\\n\\n3. **망운산 철쭉군락지**: 5월에 철쭉이 만개하는 이곳은 많은 사람들이 찾는 명소입니다. 정상까지는 약 1시간 30분 정도 소요됩니다 [참조 3].\\n - 위치: 경상남도 남해군 서면 노구리 산 786m\\n - 전화번호: 055-860-3676', 'options': None}, {'role': 'user', 'content': '남해읍 갈만한곳'}, {'role': 'assistant', 'content': '경상남도 남해읍에서 갈만한 곳으로는 다음 장소들을 추천드립니다:\\n\\n1. **남해문화원**\\n - 주소: 경상남도 남해군 남해읍 선소로 12\\n - 전화번호: 055-864-6969\\n - 관광지로 추천됩니다 [참조 1].\\n\\n2. **남해문화센터**\\n - 주소: 경상남도 남해군 남해읍 선소로 12\\n - 전화번호: 055-860-8621\\n - 봄, 여름, 가을, 겨울에도 적합하며 자가용, 렌트, 친구, 가족, 연인과 함께 방문하기 좋습니다 [참조 2].\\n\\n3. **법륜사**\\n - 주소: 경상남도 남해군 남해읍 망운로 10번길 45-1\\n - 전화번호: 055-864-3243\\n - 봄, 여름, 가을, 겨울 모두 방문할 수 있으며, 자가용, 렌트, 친구, 가족, 연인과 함께하기 좋은 장소입니다 [참조 3].'}]\n",
|
| 48 |
-
"3 [{'content': '경상남도 남해군 남해읍 선소로 12\\nY\\nhttp://www.ccnh.or.kr/html/main/main.php\\n34.8451138\\n127.8995432\\n남해문화원\\n055-864-6969\\n관광지', 'title': None, 'url': None, 'filepath': None, 'chunk_id': '0'}, {'content': '경상남도 남해군 남해읍 선소로 12\\nY\\n34.8451138\\n127.8995432\\n남해문화센터\\n055-860-8621\\n봄, 여름, 겨울, 자가용/렌트, 친구, 키즈, 연인, 우정女, 우정男, 단체\\n관광지', 'title': None, 'url': None, 'filepath': None, 'chunk_id': '0'}, {'content': '경상남도 남해군 남해읍 망운로10번길 45-1\\nY\\n34.8421872\\n127.89268\\n법흥사\\n055-864-3243\\n봄, 여름, 가을, 겨울, 자가용/렌트, 친구, 키즈, 연인, 우정女, 우정男, 효도, 나홀로\\n관광지\\n전통사찰 제104호', 'title': None, 'url': None, 'filepath': None, 'chunk_id': '0'}]\n",
|
| 49 |
-
"[{'content': '경상남도 남해군 남해읍 선소로 12\\nY\\nhttp://www.ccnh.or.kr/html/main/main.php\\n34.8451138\\n127.8995432\\n남해문화원\\n055-864-6969\\n관광지', 'title': None, 'url': None, 'filepath': None, 'chunk_id': '0'}, {'content': '경상남도 남해군 남해읍 선소로 12\\nY\\n34.8451138\\n127.8995432\\n남해문화센터\\n055-860-8621\\n봄, 여름, 겨울, 자가용/렌트, 친구, 키즈, 연인, 우정女, 우정男, 단체\\n관광지', 'title': None, 'url': None, 'filepath': None, 'chunk_id': '0'}, {'content': '경상남도 남해군 남해읍 망운로10번길 45-1\\nY\\n34.8421872\\n127.89268\\n법흥사\\n055-864-3243\\n봄, 여름, 가을, 겨울, 자가용/렌트, 친구, 키즈, 연인, 우정女, 우정男, 효도, 나홀로\\n관광지\\n전통사찰 제104호', 'title': None, 'url': None, 'filepath': None, 'chunk_id': '0'}]\n",
|
| 50 |
-
"tab!!!!!!\n",
|
| 51 |
-
"tab!!!!!!\n",
|
| 52 |
-
"tab!!!!!!\n",
|
| 53 |
-
"tab!!!!!!\n",
|
| 54 |
-
"tab!!!!!!\n",
|
| 55 |
-
"동면 갈만한곳\n",
|
| 56 |
-
"[{'role': 'user', 'metadata': {'title': None}, 'content': '서면 갈만한곳', 'options': None}, {'role': 'assistant', 'metadata': {'title': None}, 'content': '경상남도 남해군 서면에서 갈만한 곳은 다음과 같습니다:\\n\\n1. **스포츠파크**: 이곳은 남해군의 대표적인 축구 훈련장으로, 계절에 관계없이 사용 가능한 시설입니다. 전국 각지의 전지훈련객들이 많이 찾는 곳입니다 [참조 1].\\n - 위치: 경상남도 남해군 서면 스포츠파크길 74\\n - 전화번호: 055-860-8661\\n\\n2. **장항거리**: 이곳은 사계절 내내 가족 단위 관광객들이 즐기기 좋은 장소입니다 [참조 2].\\n - 위치: 경상남도 남해군 서면 남서대로1517번길 31\\n\\n3. **망운산 철쭉군락지**: 5월에 철쭉이 만개하는 이곳은 많은 사람들이 찾는 명소입니다. 정상까지는 약 1시간 30분 정도 소요됩니다 [참조 3].\\n - 위치: 경상���도 남해군 서면 노구리 산 786m\\n - 전화번호: 055-860-3676', 'options': None}, {'role': 'user', 'metadata': {'title': None}, 'content': '남해읍 갈만한곳', 'options': None}, {'role': 'assistant', 'metadata': {'title': None}, 'content': '경상남도 남해읍에서 갈만한 곳으로는 다음 장소들을 추천드립니다:\\n\\n1. **남해문화원**\\n - 주소: 경상남도 남해군 남해읍 선소로 12\\n - 전화번호: 055-864-6969\\n - 관광지로 추천됩니다 [참조 1].\\n\\n2. **남해문화센터**\\n - 주소: 경상남도 남해군 남해읍 선소로 12\\n - 전화번호: 055-860-8621\\n - 봄, 여름, 가을, 겨울에도 적합하며 자가용, 렌트, 친구, 가족, 연인과 함께 방문하기 좋습니다 [참조 2].\\n\\n3. **법륜사**\\n - 주소: 경상남도 남해군 남해읍 망운로 10번길 45-1\\n - 전화번호: 055-864-3243\\n - 봄, 여름, 가을, 겨울 모두 방문할 수 있으며, 자가용, 렌트, 친구, 가족, 연인과 함께하기 좋은 장소입니다 [참조 3].', 'options': None}, {'role': 'user', 'content': '동면 갈만한곳'}, {'role': 'assistant', 'content': '경상남도 남해군 동면에는 다양한 관광지가 있습니다. 다음은 동면과 가까운 관광지 목록입니다:\\n\\n1. **삼동면**: \\n - 관광지명: 창선교\\n - 주소: 경상남도 남해군 삼동면\\n - 전화번호: 055-860-3311\\n - 계절별로 방문 가능: 봄, 여름, 가을, 겨울\\n - 주요 테마: 자가용/렌트, 친구, 우정여행, 연인, 나홀로 여행\\n - [참조 1]\\n\\n2. **남해군 이동면**:\\n - 관광지명: 미국마을\\n - 주소: 경상남도 남해군 이동면 미국마을길\\n - 전화번호: 1588-3415\\n - 계절별로 방문 가능: 봄, 여름, 가을, 겨울\\n - 주요 테마: 마을여행, 자가용/렌트, 친구, 연인, 우정여행, 키즈, 나홀로 여행, 단체\\n - [참조 3]\\n\\n이 정보를 바탕으로 여행 계획을 세우시면 좋을 것 같습니다.'}]\n",
|
| 57 |
-
"3 [{'content': '경상남도 남해군 삼동면\\nY\\n34.830993\\n128.0010063\\n창선교\\n055-860-3311\\n봄, 여름, 가을, 겨울, 자가용/렌트, 친구, 우정女, 우정男, 나홀로\\n관광지', 'title': None, 'url': None, 'filepath': None, 'chunk_id': '0'}, {'content': '남해군 노량로183번길 27\\nY\\n34.9419198\\n127.875899\\n남해충렬사와 노량회타운\\n055-860-3311\\n관광명소, 봄, 여름, 가을, 겨울, 자가용/렌트, 친구, 연인, 우정女, 우정男, 효도, 나홀로, 단체\\n관광지', 'title': None, 'url': None, 'filepath': None, 'chunk_id': '0'}, {'content': '경상남도 남해군 이동면 미국마을길\\n미국형 전통 건축양식인 고급 민박형 팬션과 전원주거가 결합된 주택을 건립하여 특색 있는 관광인프라를 구축하고 있다.\\nY\\n34.7806685\\n127.9281169\\n미국마을\\n1588-3415\\n마을여행, 봄, 여름, 가을, 겨울, 자가용/렌트, 친구, 키즈, 연인, 우정女, 우정男, 효도, 단체\\n관광지', 'title': None, 'url': None, 'filepath': None, 'chunk_id': '0'}]\n",
|
| 58 |
-
"[{'content': '경상남도 남해군 삼동면\\nY\\n34.830993\\n128.0010063\\n창선교\\n055-860-3311\\n봄, 여름, 가을, 겨울, 자가용/렌트, 친구, 우정女, 우정男, 나홀로\\n관광지', 'title': None, 'url': None, 'filepath': None, 'chunk_id': '0'}, {'content': '남해군 노량로183번길 27\\nY\\n34.9419198\\n127.875899\\n남해충렬사와 노량회타운\\n055-860-3311\\n관광명소, 봄, 여름, 가을, 겨울, 자가용/렌트, 친구, 연인, 우정女, 우정男, 효도, 나홀로, 단체\\n관광지', 'title': None, 'url': None, 'filepath': None, 'chunk_id': '0'}, {'content': '경상남도 남해군 이동면 미국마을길\\n미국형 전통 건축양식인 고급 민박형 팬션과 전원주거가 결합된 주택을 건립하여 특색 있는 관광인프라를 구축하고 있다.\\nY\\n34.7806685\\n127.9281169\\n미국마을\\n1588-3415\\n마을여행, 봄, 여름, 가을, 겨울, 자가용/렌트, 친구, 키즈, 연인, 우정女, 우정男, 효도, 단체\\n관광지', 'title': None, 'url': None, 'filepath': None, 'chunk_id': '0'}]\n",
|
| 59 |
-
"tab!!!!!!\n",
|
| 60 |
-
"tab!!!!!!\n",
|
| 61 |
-
"tab!!!!!!\n"
|
| 62 |
-
]
|
| 63 |
-
}
|
| 64 |
-
],
|
| 65 |
-
"source": [
|
| 66 |
-
"import gradio as gr\n",
|
| 67 |
-
"import requests\n",
|
| 68 |
-
"import re\n",
|
| 69 |
-
"\n",
|
| 70 |
-
"# endpoint : \n",
|
| 71 |
-
"deployment_name = \"fimtrus-gpt-4o-ncus\"\n",
|
| 72 |
-
"endpoint = \"https://fimtrus-openai-ncus.openai.azure.com/openai/deployments/{}/chat/completions\".format(deployment_name)\n",
|
| 73 |
-
"api_key = \"FP7k76c0BGmz4MVot1LVqdtqcmQaKBeerYdFyXzW4NXN0940rRfEJQQJ99BCACHrzpqXJ3w3AAABACOG8189\"\n",
|
| 74 |
-
"\n",
|
| 75 |
-
"ai_search_endpoint = \"https://fimtrus-ai-search3.search.windows.net\"\n",
|
| 76 |
-
"ai_search_key = \"lw8TYxNHT14hpM5oJQhCL3iOxR4PR494dV4RLDaiwzAzSeBecA5i\"\n",
|
| 77 |
-
"ai_search_index_name = \"travel-index-microsoft2\"\n",
|
| 78 |
-
"ai_search_semantic = \"travel-semantic\"\n",
|
| 79 |
-
"\n",
|
| 80 |
-
"\n",
|
| 81 |
-
"def request_gpt(prompt):\n",
|
| 82 |
-
" query_params = {\n",
|
| 83 |
-
" \"api-version\": \"2025-02-01-preview\"\n",
|
| 84 |
-
" }\n",
|
| 85 |
-
" headers = {\n",
|
| 86 |
-
" \"Content-Type\": \"application/json\",\n",
|
| 87 |
-
" \"api-key\": api_key\n",
|
| 88 |
-
" }\n",
|
| 89 |
-
" \n",
|
| 90 |
-
" body = {\n",
|
| 91 |
-
" \"data_sources\": [\n",
|
| 92 |
-
" {\n",
|
| 93 |
-
" \"type\": \"azure_search\",\n",
|
| 94 |
-
" \"parameters\": {\n",
|
| 95 |
-
" \"endpoint\": ai_search_endpoint,\n",
|
| 96 |
-
" \"index_name\": ai_search_index_name,\n",
|
| 97 |
-
" \"semantic_configuration\": ai_search_semantic,\n",
|
| 98 |
-
" \"query_type\": \"semantic\",\n",
|
| 99 |
-
" \"fields_mapping\": {},\n",
|
| 100 |
-
" \"in_scope\": True,\n",
|
| 101 |
-
" \"filter\": None,\n",
|
| 102 |
-
" \"strictness\": 3,\n",
|
| 103 |
-
" \"top_n_documents\": 3,\n",
|
| 104 |
-
" \"authentication\": {\n",
|
| 105 |
-
" \"type\": \"api_key\",\n",
|
| 106 |
-
" \"key\": ai_search_key\n",
|
| 107 |
-
" },\n",
|
| 108 |
-
" \"key\": ai_search_key\n",
|
| 109 |
-
" }\n",
|
| 110 |
-
" }\n",
|
| 111 |
-
" ],\n",
|
| 112 |
-
" \"messages\": [\n",
|
| 113 |
-
" {\n",
|
| 114 |
-
" \"role\": \"system\",\n",
|
| 115 |
-
" \"content\": \"사용자가 정보를 찾는 데 도움이 되는 AI 도우미입니다.\"\n",
|
| 116 |
-
" },\n",
|
| 117 |
-
" {\n",
|
| 118 |
-
" \"role\": \"user\",\n",
|
| 119 |
-
" \"content\": prompt\n",
|
| 120 |
-
" }\n",
|
| 121 |
-
" ],\n",
|
| 122 |
-
" \"temperature\": 0.7,\n",
|
| 123 |
-
" \"top_p\": 0.95,\n",
|
| 124 |
-
" \"max_tokens\": 800,\n",
|
| 125 |
-
" \"stop\": None,\n",
|
| 126 |
-
" \"stream\": False,\n",
|
| 127 |
-
" \"frequency_penalty\": 0,\n",
|
| 128 |
-
" \"presence_penalty\": 0\n",
|
| 129 |
-
" }\n",
|
| 130 |
-
"\n",
|
| 131 |
-
" response = requests.post(endpoint, params=query_params, headers=headers, json=body)\n",
|
| 132 |
-
" \n",
|
| 133 |
-
" if response.status_code == 200:\n",
|
| 134 |
-
" response_json = response.json()\n",
|
| 135 |
-
" message = response_json['choices'][0]['message']\n",
|
| 136 |
-
" content = message['content']\n",
|
| 137 |
-
" \n",
|
| 138 |
-
" content = re.sub(r'\\[doc(\\d+)\\]', r'[참조 \\1]', content)\n",
|
| 139 |
-
" \n",
|
| 140 |
-
" if message['context']:\n",
|
| 141 |
-
" citation_list = message['context']['citations']\n",
|
| 142 |
-
" else:\n",
|
| 143 |
-
" citation_list = list()\n",
|
| 144 |
-
" return content, citation_list\n",
|
| 145 |
-
" else:\n",
|
| 146 |
-
" return \"\", list()\n",
|
| 147 |
-
"\n",
|
| 148 |
-
"#############################################################################\n",
|
| 149 |
-
"\n",
|
| 150 |
-
"\n",
|
| 151 |
-
"with gr.Blocks() as demo:\n",
|
| 152 |
-
" \n",
|
| 153 |
-
" citation_state = gr.State([])\n",
|
| 154 |
-
" \n",
|
| 155 |
-
" def click_send(prompt, histories):\n",
|
| 156 |
-
" print(prompt)\n",
|
| 157 |
-
" content, citation_list = request_gpt(prompt=prompt)\n",
|
| 158 |
-
" message_list = [{\"role\": \"user\", \"content\": prompt}, {\"role\": \"assistant\", \"content\": content}]\n",
|
| 159 |
-
" histories.extend(message_list)\n",
|
| 160 |
-
" \n",
|
| 161 |
-
" print(histories)\n",
|
| 162 |
-
" print(len(citation_list), citation_list)\n",
|
| 163 |
-
" return histories, citation_list, \"\"\n",
|
| 164 |
-
" \n",
|
| 165 |
-
" def select_tab(citation):\n",
|
| 166 |
-
" print(\"tab!!!!!!\")\n",
|
| 167 |
-
" return gr.Textbox(label=\"\", value=citation, lines=10, max_lines=10, visible=True)\n",
|
| 168 |
-
" \n",
|
| 169 |
-
" gr.Markdown(\"# 나의 GPT 월드\")\n",
|
| 170 |
-
" \n",
|
| 171 |
-
" with gr.Row():\n",
|
| 172 |
-
" chatbot = gr.Chatbot(label=\"나의 GPT\", type=\"messages\", scale=3)\n",
|
| 173 |
-
" \n",
|
| 174 |
-
" with gr.Column(scale=1): \n",
|
| 175 |
-
" @gr.render(inputs=[citation_state])\n",
|
| 176 |
-
" def render_citations(citations):\n",
|
| 177 |
-
" print(citations)\n",
|
| 178 |
-
" for index in range(len(citations)):\n",
|
| 179 |
-
" content = citations[index]['content']\n",
|
| 180 |
-
" key = \"참조{}\".format(index + 1)\n",
|
| 181 |
-
" if index == 0:\n",
|
| 182 |
-
" gr.Tab(\"\", id=-1, visible=False)\n",
|
| 183 |
-
" with gr.Tab(key) as tab:\n",
|
| 184 |
-
" citation_textbox = gr.Textbox(label=\"\", value=content, lines=10, max_lines=10, visible=False)\n",
|
| 185 |
-
" tab.select(fn=select_tab, inputs=[citation_textbox], outputs=[citation_textbox])\n",
|
| 186 |
-
" \n",
|
| 187 |
-
" with gr.Row():\n",
|
| 188 |
-
" prompt_textbox = gr.Textbox(label=\"프롬프트\", placeholder=\"프롬프트를 입력하세요.\", scale=6)\n",
|
| 189 |
-
" send_button = gr.Button(\"전송\", scale=1)\n",
|
| 190 |
-
" \n",
|
| 191 |
-
" send_button.click(click_send, inputs=[prompt_textbox, chatbot], outputs=[chatbot, citation_state, prompt_textbox])\n",
|
| 192 |
-
" prompt_textbox.submit(click_send, inputs=[prompt_textbox, chatbot], outputs=[chatbot, citation_state, prompt_textbox])\n",
|
| 193 |
-
" \n",
|
| 194 |
-
" \n",
|
| 195 |
-
"demo.launch()\n",
|
| 196 |
-
"\n"
|
| 197 |
-
]
|
| 198 |
-
},
|
| 199 |
-
{
|
| 200 |
-
"cell_type": "code",
|
| 201 |
-
"execution_count": null,
|
| 202 |
-
"metadata": {},
|
| 203 |
-
"outputs": [],
|
| 204 |
-
"source": []
|
| 205 |
-
}
|
| 206 |
-
],
|
| 207 |
-
"metadata": {
|
| 208 |
-
"kernelspec": {
|
| 209 |
-
"display_name": "openai",
|
| 210 |
-
"language": "python",
|
| 211 |
-
"name": "python3"
|
| 212 |
-
},
|
| 213 |
-
"language_info": {
|
| 214 |
-
"codemirror_mode": {
|
| 215 |
-
"name": "ipython",
|
| 216 |
-
"version": 3
|
| 217 |
-
},
|
| 218 |
-
"file_extension": ".py",
|
| 219 |
-
"mimetype": "text/x-python",
|
| 220 |
-
"name": "python",
|
| 221 |
-
"nbconvert_exporter": "python",
|
| 222 |
-
"pygments_lexer": "ipython3",
|
| 223 |
-
"version": "3.11.9"
|
| 224 |
-
}
|
| 225 |
-
},
|
| 226 |
-
"nbformat": 4,
|
| 227 |
-
"nbformat_minor": 2
|
| 228 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
requirements.txt
DELETED
|
@@ -1 +0,0 @@
|
|
| 1 |
-
huggingface_hub==0.25.2
|
|
|
|
|
|