Spaces:
openfree
/
Running on CPU Upgrade

ginipick commited on
Commit
7c3b41f
ยท
verified ยท
1 Parent(s): e12dec3

Update app-backup2.py

Browse files
Files changed (1) hide show
  1. app-backup2.py +205 -31
app-backup2.py CHANGED
@@ -10,7 +10,74 @@ from requests.packages.urllib3.util.retry import Retry
10
  from openai import OpenAI
11
  from bs4 import BeautifulSoup
12
  import re # re ๋ชจ๋“ˆ ์ถ”๊ฐ€
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
  ACCESS_TOKEN = os.getenv("HF_TOKEN")
15
  if not ACCESS_TOKEN:
16
  raise ValueError("HF_TOKEN environment variable is not set")
@@ -725,6 +792,7 @@ def search_global(query, region, articles_state_global):
725
  css = """
726
  /* ์ „์—ญ ์Šคํƒ€์ผ */
727
  footer {visibility: hidden;}
 
728
  /* ๋ ˆ์ด์•„์›ƒ ์ปจํ…Œ์ด๋„ˆ */
729
  #status_area {
730
  background: rgba(255, 255, 255, 0.9);
@@ -733,33 +801,40 @@ footer {visibility: hidden;}
733
  margin-bottom: 20px;
734
  box-shadow: 0 2px 5px rgba(0,0,0,0.1);
735
  }
 
736
  #results_area {
737
  padding: 10px;
738
  margin-top: 10px;
739
  }
 
740
  /* ํƒญ ์Šคํƒ€์ผ */
741
  .tabs {
742
  border-bottom: 2px solid #ddd !important;
743
  margin-bottom: 20px !important;
744
  }
 
745
  .tab-nav {
746
  border-bottom: none !important;
747
  margin-bottom: 0 !important;
748
  }
 
749
  .tab-nav button {
750
  font-weight: bold !important;
751
  padding: 10px 20px !important;
752
  }
 
753
  .tab-nav button.selected {
754
  border-bottom: 2px solid #1f77b4 !important;
755
  color: #1f77b4 !important;
756
  }
 
757
  /* ์ƒํƒœ ๋ฉ”์‹œ์ง€ */
758
  #status_area .markdown-text {
759
  font-size: 1.1em;
760
  color: #2c3e50;
761
  padding: 10px 0;
762
  }
 
763
  /* ๊ธฐ๋ณธ ์ปจํ…Œ์ด๋„ˆ */
764
  .group {
765
  border: 1px solid #eee;
@@ -768,16 +843,19 @@ footer {visibility: hidden;}
768
  border-radius: 5px;
769
  background: white;
770
  }
 
771
  /* ๋ฒ„ํŠผ ์Šคํƒ€์ผ */
772
  .primary-btn {
773
  background: #1f77b4 !important;
774
  border: none !important;
775
  }
 
776
  /* ์ž…๋ ฅ ํ•„๋“œ */
777
  .textbox {
778
  border: 1px solid #ddd !important;
779
  border-radius: 4px !important;
780
  }
 
781
  /* ํ”„๋กœ๊ทธ๋ ˆ์Šค๋ฐ” ์ปจํ…Œ์ด๋„ˆ */
782
  .progress-container {
783
  position: fixed;
@@ -788,6 +866,7 @@ footer {visibility: hidden;}
788
  background: #e0e0e0;
789
  z-index: 1000;
790
  }
 
791
  /* ํ”„๋กœ๊ทธ๋ ˆ์Šค๋ฐ” */
792
  .progress-bar {
793
  height: 100%;
@@ -796,6 +875,7 @@ footer {visibility: hidden;}
796
  transition: width 0.3s ease;
797
  animation: progress-glow 1.5s ease-in-out infinite;
798
  }
 
799
  /* ํ”„๋กœ๊ทธ๋ ˆ์Šค ํ…์ŠคํŠธ */
800
  .progress-text {
801
  position: fixed;
@@ -810,6 +890,7 @@ footer {visibility: hidden;}
810
  z-index: 1001;
811
  box-shadow: 0 2px 5px rgba(0,0,0,0.2);
812
  }
 
813
  /* ํ”„๋กœ๊ทธ๋ ˆ์Šค๋ฐ” ์• ๋‹ˆ๋ฉ”์ด์…˜ */
814
  @keyframes progress-glow {
815
  0% {
@@ -822,6 +903,7 @@ footer {visibility: hidden;}
822
  box-shadow: 0 0 5px rgba(33, 150, 243, 0.5);
823
  }
824
  }
 
825
  /* ๋ฐ˜์‘ํ˜• ๋””์ž์ธ */
826
  @media (max-width: 768px) {
827
  .group {
@@ -834,27 +916,32 @@ footer {visibility: hidden;}
834
  padding: 3px 10px;
835
  }
836
  }
 
837
  /* ๋กœ๋”ฉ ์ƒํƒœ ํ‘œ์‹œ ๊ฐœ์„  */
838
  .loading {
839
  opacity: 0.7;
840
  pointer-events: none;
841
  transition: opacity 0.3s ease;
842
  }
 
843
  /* ๊ฒฐ๊ณผ ์ปจํ…Œ์ด๋„ˆ ์• ๋‹ˆ๋ฉ”์ด์…˜ */
844
  .group {
845
  transition: all 0.3s ease;
846
  opacity: 0;
847
  transform: translateY(20px);
848
  }
 
849
  .group.visible {
850
  opacity: 1;
851
  transform: translateY(0);
852
  }
 
853
  /* Examples ์Šคํƒ€์ผ๋ง */
854
  .examples-table {
855
  margin-top: 10px !important;
856
  margin-bottom: 20px !important;
857
  }
 
858
  .examples-table button {
859
  background-color: #f0f0f0 !important;
860
  border: 1px solid #ddd !important;
@@ -863,11 +950,13 @@ footer {visibility: hidden;}
863
  margin: 2px !important;
864
  transition: all 0.3s ease !important;
865
  }
 
866
  .examples-table button:hover {
867
  background-color: #e0e0e0 !important;
868
  transform: translateY(-1px) !important;
869
  box-shadow: 0 2px 5px rgba(0,0,0,0.1) !important;
870
  }
 
871
  .examples-table .label {
872
  font-weight: bold !important;
873
  color: #444 !important;
@@ -946,17 +1035,21 @@ def respond(url, history, system_message, max_tokens, temperature, top_p):
946
  article_content = get_article_content(url)
947
 
948
  translation_prompt = f"""๋‹ค์Œ ์˜๋ฌธ ๊ธฐ์‚ฌ๋ฅผ ํ•œ๊ตญ์–ด๋กœ ๋ฒˆ์—ญํ•˜๊ณ  ๊ธฐ์‚ฌ๋ฅผ ์ž‘์„ฑํ•ด์ฃผ์„ธ์š”.
 
949
  1๋‹จ๊ณ„: ์ „๋ฌธ ๋ฒˆ์—ญ
950
  ===๋ฒˆ์—ญ ์‹œ์ž‘===
951
  {article_content}
952
  ===๋ฒˆ์—ญ ๋===
 
953
  2๋‹จ๊ณ„: ๊ธฐ์‚ฌ ์ž‘์„ฑ ๊ฐ€์ด๋“œ๋ผ์ธ
954
  ๋‹ค์Œ ์š”๊ตฌ์‚ฌํ•ญ์— ๋”ฐ๋ผ ํ•œ๊ตญ์–ด ๊ธฐ์‚ฌ๋ฅผ ์ž‘์„ฑํ•˜์„ธ์š”:
 
955
  1. ๊ตฌ์กฐ
956
  - ํ—ค๋“œ๋ผ์ธ: ํ•ต์‹ฌ ๋‚ด์šฉ์„ ๋‹ด์€ ๊ฐ•๋ ฅํ•œ ์ œ๋ชฉ
957
  - ๋ถ€์ œ๋ชฉ: ํ—ค๋“œ๋ผ์ธ ๋ณด์™„ ์„ค๋ช…
958
  - ๋ฆฌ๋“œ๋ฌธ: ๊ธฐ์‚ฌ์˜ ํ•ต์‹ฌ์„ ์š”์•ฝํ•œ ์ฒซ ๋ฌธ๋‹จ
959
  - ๋ณธ๋ฌธ: ์ƒ์„ธ ๋‚ด์šฉ ์ „๊ฐœ
 
960
  2. ์ž‘์„ฑ ๊ทœ์น™
961
  - ๊ฐ๊ด€์ ์ด๊ณ  ์ •ํ™•ํ•œ ์‚ฌ์‹ค ์ „๋‹ฌ
962
  - ๋ฌธ์žฅ์€ '๋‹ค.'๋กœ ์ข…๊ฒฐ
@@ -964,10 +1057,12 @@ def respond(url, history, system_message, max_tokens, temperature, top_p):
964
  - ์ธ์šฉ๊ตฌ๋Š” ๋”ฐ์˜ดํ‘œ ์ฒ˜๋ฆฌ
965
  - ํ•ต์‹ฌ ์ •๋ณด๋ฅผ ์•ž๋ถ€๋ถ„์— ๋ฐฐ์น˜
966
  - ์ „๋ฌธ ์šฉ์–ด๋Š” ์ ์ ˆํ•œ ์„ค๋ช… ์ถ”๊ฐ€
 
967
  3. ํ˜•์‹
968
  - ์ ์ ˆํ•œ ๋‹จ๋ฝ ๊ตฌ๋ถ„
969
  - ์ฝ๊ธฐ ์‰ฌ์šด ๋ฌธ์žฅ ๊ธธ์ด
970
  - ๋…ผ๋ฆฌ์ ์ธ ์ •๋ณด ๊ตฌ์„ฑ
 
971
  ๊ฐ ๋‹จ๊ณ„๋Š” '===๋ฒˆ์—ญ===', '===๊ธฐ์‚ฌ==='๋กœ ๋ช…ํ™•ํžˆ ๊ตฌ๋ถ„ํ•˜์—ฌ ์ถœ๋ ฅํ•˜์„ธ์š”.
972
  """
973
 
@@ -1004,9 +1099,81 @@ def respond(url, history, system_message, max_tokens, temperature, top_p):
1004
 
1005
  return history
1006
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1007
  with gr.Blocks(theme="Yntec/HaleyCH_Theme_Orange", css=css, title="NewsAI ์„œ๋น„์Šค") as iface:
 
 
1008
  with gr.Tabs():
1009
- # ๊ตญ๊ฐ€๋ณ„ ํƒญ
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1010
  with gr.Tab("๊ตญ๊ฐ€๋ณ„"):
1011
  gr.Markdown("๊ฒ€์ƒ‰์–ด๋ฅผ ์ž…๋ ฅํ•˜๊ณ  ์›ํ•˜๋Š” ๊ตญ๊ฐ€(ํ•œ๊ตญ ์ œ์™ธ)๋ฅผ๋ฅผ ์„ ํƒํ•˜๋ฉด, ๊ฒ€์ƒ‰์–ด์™€ ์ผ์น˜ํ•˜๋Š” 24์‹œ๊ฐ„ ์ด๋‚ด ๋‰ด์Šค๋ฅผ ์ตœ๋Œ€ 100๊ฐœ ์ถœ๋ ฅํ•ฉ๋‹ˆ๋‹ค.")
1012
  gr.Markdown("๊ตญ๊ฐ€ ์„ ํƒํ›„ ๊ฒ€์ƒ‰์–ด์— 'ํ•œ๊ธ€'์„ ์ž…๋ ฅํ•˜๋ฉด ํ˜„์ง€ ์–ธ์–ด๋กœ ๋ฒˆ์—ญ๋˜์–ด ๊ฒ€์ƒ‰ํ•ฉ๋‹ˆ๋‹ค. ์˜ˆ: 'Taiwan' ๊ตญ๊ฐ€ ์„ ํƒํ›„ '์‚ผ์„ฑ' ์ž…๋ ฅ์‹œ 'ไธ‰ๆ˜Ÿ'์œผ๋กœ ์ž๋™ ๊ฒ€์ƒ‰")
@@ -1049,7 +1216,6 @@ with gr.Blocks(theme="Yntec/HaleyCH_Theme_Orange", css=css, title="NewsAI ์„œ๋น„
1049
  translated_query_display = gr.Markdown(visible=False)
1050
  search_button = gr.Button("๊ฒ€์ƒ‰", variant="primary")
1051
 
1052
-
1053
  progress = gr.Progress()
1054
  articles_state = gr.State([])
1055
 
@@ -1107,8 +1273,7 @@ with gr.Blocks(theme="Yntec/HaleyCH_Theme_Orange", css=css, title="NewsAI ์„œ๋น„
1107
  'index': i,
1108
  })
1109
 
1110
-
1111
- # AI ๋ฒˆ์—ญ ํƒญ ์ถ”๊ฐ€
1112
  with gr.Tab("AI ๊ธฐ์‚ฌ ์ƒ์„ฑ"):
1113
  gr.Markdown("๋‰ด์Šค URL์„ ์ž…๋ ฅํ•˜๋ฉด AI๊ฐ€ ํ•œ๊ตญ์–ด๋กœ ๋ฒˆ์—ญํ•˜์—ฌ ๊ธฐ์‚ฌ ํ˜•์‹์œผ๋กœ ์ž‘์„ฑํ•ฉ๋‹ˆ๋‹ค.")
1114
  gr.Markdown("์ด๋ฏธ์ง€ ์ƒ์„ฑ: https://huggingface.co/spaces/ginipick/FLUXllama ")
@@ -1122,10 +1287,13 @@ with gr.Blocks(theme="Yntec/HaleyCH_Theme_Orange", css=css, title="NewsAI ์„œ๋น„
1122
  placeholder="https://..."
1123
  )
1124
 
1125
- with gr.Accordion("๊ณ ๊ธ‰ ์„ค์ •", open=False):
 
 
1126
 
 
1127
  system_message = gr.Textbox(
1128
- value="""You are a professional translator and journalist. Follow these steps strictly:
1129
  1. TRANSLATION
1130
  - Start with ===๋ฒˆ์—ญ=== marker
1131
  - Provide accurate Korean translation
@@ -1155,14 +1323,12 @@ with gr.Blocks(theme="Yntec/HaleyCH_Theme_Orange", css=css, title="NewsAI ์„œ๋น„
1155
  - Clearly separate each section with markers
1156
  - Never skip or combine steps
1157
  - Ensure image prompts align with article content""",
1158
- label="System message"
1159
- )
1160
 
1161
-
1162
-
1163
  max_tokens = gr.Slider(
1164
  minimum=1,
1165
- maximum=7800,
1166
  value=7624,
1167
  step=1,
1168
  label="Max new tokens"
@@ -1181,26 +1347,7 @@ with gr.Blocks(theme="Yntec/HaleyCH_Theme_Orange", css=css, title="NewsAI ์„œ๋น„
1181
  step=0.05,
1182
  label="Top-P"
1183
  )
1184
-
1185
- translate_button = gr.Button("๊ธฐ์‚ฌ ์ƒ์„ฑ", variant="primary")
1186
-
1187
- # ์ด๋ฒคํŠธ ์—ฐ๊ฒฐ
1188
- translate_button.click(
1189
- fn=respond,
1190
- inputs=[
1191
- url_input,
1192
- chatbot,
1193
- system_message,
1194
- max_tokens,
1195
- temperature,
1196
- top_p,
1197
- ],
1198
- outputs=chatbot
1199
- )
1200
-
1201
-
1202
 
1203
-
1204
  # ์ด๋ฒคํŠธ ์—ฐ๊ฒฐ ๋ถ€๋ถ„
1205
  # ๊ตญ๊ฐ€๋ณ„ ํƒญ ์ด๋ฒคํŠธ
1206
  search_outputs = [status_message, translated_query_display, gr.Markdown(visible=False)]
@@ -1234,6 +1381,33 @@ with gr.Blocks(theme="Yntec/HaleyCH_Theme_Orange", css=css, title="NewsAI ์„œ๋น„
1234
  show_progress=True
1235
  )
1236
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1237
  iface.launch(
1238
  server_name="0.0.0.0",
1239
  server_port=7860,
@@ -1241,4 +1415,4 @@ iface.launch(
1241
  auth=("gini","pick"),
1242
  ssl_verify=False,
1243
  show_error=True
1244
- )
 
10
  from openai import OpenAI
11
  from bs4 import BeautifulSoup
12
  import re # re ๋ชจ๋“ˆ ์ถ”๊ฐ€
13
+ import json
14
+ import os
15
+ from datetime import datetime
16
+ import sqlite3
17
+ import pathlib
18
+
19
+ # DB ์ดˆ๊ธฐํ™” ํ•จ์ˆ˜
20
+ def init_db():
21
+ db_path = pathlib.Path("search_results.db")
22
+ conn = sqlite3.connect(db_path)
23
+ c = conn.cursor()
24
+ c.execute('''CREATE TABLE IF NOT EXISTS searches
25
+ (id INTEGER PRIMARY KEY AUTOINCREMENT,
26
+ keyword TEXT,
27
+ country TEXT,
28
+ results TEXT,
29
+ timestamp DATETIME DEFAULT CURRENT_TIMESTAMP)''')
30
+ conn.commit()
31
+ conn.close()
32
+
33
+ # ๊ฒ€์ƒ‰ ๊ฒฐ๊ณผ ์ €์žฅ ํ•จ์ˆ˜
34
+ def save_to_db(keyword, country, results):
35
+ conn = sqlite3.connect("search_results.db")
36
+ c = conn.cursor()
37
+ c.execute("INSERT INTO searches (keyword, country, results) VALUES (?, ?, ?)",
38
+ (keyword, country, json.dumps(results)))
39
+ conn.commit()
40
+ conn.close()
41
+
42
+ # DB์—์„œ ๊ฒ€์ƒ‰ ๊ฒฐ๊ณผ ๋ถˆ๋Ÿฌ์˜ค๊ธฐ ํ•จ์ˆ˜
43
+ def load_from_db(keyword, country):
44
+ conn = sqlite3.connect("search_results.db")
45
+ c = conn.cursor()
46
+ c.execute("SELECT results, timestamp FROM searches WHERE keyword=? AND country=? ORDER BY timestamp DESC LIMIT 1",
47
+ (keyword, country))
48
+ result = c.fetchone()
49
+ conn.close()
50
+ if result:
51
+ return json.loads(result[0]), result[1]
52
+ return None, None
53
+
54
+ # ์‚ผ์„ฑ/๋ฏธ๊ตญ ๊ฒ€์ƒ‰ ํ•จ์ˆ˜
55
+ def search_samsung_us():
56
+ error_message, articles = serphouse_search("samsung", "United States")
57
+ if not error_message and articles:
58
+ save_to_db("samsung", "United States", articles)
59
+ return display_results(articles)
60
+ return "๊ฒ€์ƒ‰ ๊ฒฐ๊ณผ๊ฐ€ ์—†์Šต๋‹ˆ๋‹ค."
61
 
62
+ # DB์—์„œ ์‚ผ์„ฑ/๋ฏธ๊ตญ ๊ฒฐ๊ณผ ๋ถˆ๋Ÿฌ์˜ค๊ธฐ ํ•จ์ˆ˜
63
+ def load_samsung_us():
64
+ results, timestamp = load_from_db("samsung", "United States")
65
+ if results:
66
+ return f"์ €์žฅ ์‹œ๊ฐ„: {timestamp}\n\n" + display_results(results)
67
+ return "์ €์žฅ๋œ ๊ฒฐ๊ณผ๊ฐ€ ์—†์Šต๋‹ˆ๋‹ค."
68
+
69
+ # ๊ฒฐ๊ณผ ํ‘œ์‹œ ํ•จ์ˆ˜
70
+ def display_results(articles):
71
+ output = ""
72
+ for idx, article in enumerate(articles, 1):
73
+ output += f"### {idx}. {article['title']}\n"
74
+ output += f"์ถœ์ฒ˜: {article['channel']}\n"
75
+ output += f"์‹œ๊ฐ„: {article['time']}\n"
76
+ output += f"๋งํฌ: {article['link']}\n"
77
+ output += f"์š”์•ฝ: {article['snippet']}\n\n"
78
+ return output
79
+
80
+
81
  ACCESS_TOKEN = os.getenv("HF_TOKEN")
82
  if not ACCESS_TOKEN:
83
  raise ValueError("HF_TOKEN environment variable is not set")
 
792
  css = """
793
  /* ์ „์—ญ ์Šคํƒ€์ผ */
794
  footer {visibility: hidden;}
795
+
796
  /* ๋ ˆ์ด์•„์›ƒ ์ปจํ…Œ์ด๋„ˆ */
797
  #status_area {
798
  background: rgba(255, 255, 255, 0.9);
 
801
  margin-bottom: 20px;
802
  box-shadow: 0 2px 5px rgba(0,0,0,0.1);
803
  }
804
+
805
  #results_area {
806
  padding: 10px;
807
  margin-top: 10px;
808
  }
809
+
810
  /* ํƒญ ์Šคํƒ€์ผ */
811
  .tabs {
812
  border-bottom: 2px solid #ddd !important;
813
  margin-bottom: 20px !important;
814
  }
815
+
816
  .tab-nav {
817
  border-bottom: none !important;
818
  margin-bottom: 0 !important;
819
  }
820
+
821
  .tab-nav button {
822
  font-weight: bold !important;
823
  padding: 10px 20px !important;
824
  }
825
+
826
  .tab-nav button.selected {
827
  border-bottom: 2px solid #1f77b4 !important;
828
  color: #1f77b4 !important;
829
  }
830
+
831
  /* ์ƒํƒœ ๋ฉ”์‹œ์ง€ */
832
  #status_area .markdown-text {
833
  font-size: 1.1em;
834
  color: #2c3e50;
835
  padding: 10px 0;
836
  }
837
+
838
  /* ๊ธฐ๋ณธ ์ปจํ…Œ์ด๋„ˆ */
839
  .group {
840
  border: 1px solid #eee;
 
843
  border-radius: 5px;
844
  background: white;
845
  }
846
+
847
  /* ๋ฒ„ํŠผ ์Šคํƒ€์ผ */
848
  .primary-btn {
849
  background: #1f77b4 !important;
850
  border: none !important;
851
  }
852
+
853
  /* ์ž…๋ ฅ ํ•„๋“œ */
854
  .textbox {
855
  border: 1px solid #ddd !important;
856
  border-radius: 4px !important;
857
  }
858
+
859
  /* ํ”„๋กœ๊ทธ๋ ˆ์Šค๋ฐ” ์ปจํ…Œ์ด๋„ˆ */
860
  .progress-container {
861
  position: fixed;
 
866
  background: #e0e0e0;
867
  z-index: 1000;
868
  }
869
+
870
  /* ํ”„๋กœ๊ทธ๋ ˆ์Šค๋ฐ” */
871
  .progress-bar {
872
  height: 100%;
 
875
  transition: width 0.3s ease;
876
  animation: progress-glow 1.5s ease-in-out infinite;
877
  }
878
+
879
  /* ํ”„๋กœ๊ทธ๋ ˆ์Šค ํ…์ŠคํŠธ */
880
  .progress-text {
881
  position: fixed;
 
890
  z-index: 1001;
891
  box-shadow: 0 2px 5px rgba(0,0,0,0.2);
892
  }
893
+
894
  /* ํ”„๋กœ๊ทธ๋ ˆ์Šค๋ฐ” ์• ๋‹ˆ๋ฉ”์ด์…˜ */
895
  @keyframes progress-glow {
896
  0% {
 
903
  box-shadow: 0 0 5px rgba(33, 150, 243, 0.5);
904
  }
905
  }
906
+
907
  /* ๋ฐ˜์‘ํ˜• ๋””์ž์ธ */
908
  @media (max-width: 768px) {
909
  .group {
 
916
  padding: 3px 10px;
917
  }
918
  }
919
+
920
  /* ๋กœ๋”ฉ ์ƒํƒœ ํ‘œ์‹œ ๊ฐœ์„  */
921
  .loading {
922
  opacity: 0.7;
923
  pointer-events: none;
924
  transition: opacity 0.3s ease;
925
  }
926
+
927
  /* ๊ฒฐ๊ณผ ์ปจํ…Œ์ด๋„ˆ ์• ๋‹ˆ๋ฉ”์ด์…˜ */
928
  .group {
929
  transition: all 0.3s ease;
930
  opacity: 0;
931
  transform: translateY(20px);
932
  }
933
+
934
  .group.visible {
935
  opacity: 1;
936
  transform: translateY(0);
937
  }
938
+
939
  /* Examples ์Šคํƒ€์ผ๋ง */
940
  .examples-table {
941
  margin-top: 10px !important;
942
  margin-bottom: 20px !important;
943
  }
944
+
945
  .examples-table button {
946
  background-color: #f0f0f0 !important;
947
  border: 1px solid #ddd !important;
 
950
  margin: 2px !important;
951
  transition: all 0.3s ease !important;
952
  }
953
+
954
  .examples-table button:hover {
955
  background-color: #e0e0e0 !important;
956
  transform: translateY(-1px) !important;
957
  box-shadow: 0 2px 5px rgba(0,0,0,0.1) !important;
958
  }
959
+
960
  .examples-table .label {
961
  font-weight: bold !important;
962
  color: #444 !important;
 
1035
  article_content = get_article_content(url)
1036
 
1037
  translation_prompt = f"""๋‹ค์Œ ์˜๋ฌธ ๊ธฐ์‚ฌ๋ฅผ ํ•œ๊ตญ์–ด๋กœ ๋ฒˆ์—ญํ•˜๊ณ  ๊ธฐ์‚ฌ๋ฅผ ์ž‘์„ฑํ•ด์ฃผ์„ธ์š”.
1038
+
1039
  1๋‹จ๊ณ„: ์ „๋ฌธ ๋ฒˆ์—ญ
1040
  ===๋ฒˆ์—ญ ์‹œ์ž‘===
1041
  {article_content}
1042
  ===๋ฒˆ์—ญ ๋===
1043
+
1044
  2๋‹จ๊ณ„: ๊ธฐ์‚ฌ ์ž‘์„ฑ ๊ฐ€์ด๋“œ๋ผ์ธ
1045
  ๋‹ค์Œ ์š”๊ตฌ์‚ฌํ•ญ์— ๋”ฐ๋ผ ํ•œ๊ตญ์–ด ๊ธฐ์‚ฌ๋ฅผ ์ž‘์„ฑํ•˜์„ธ์š”:
1046
+
1047
  1. ๊ตฌ์กฐ
1048
  - ํ—ค๋“œ๋ผ์ธ: ํ•ต์‹ฌ ๋‚ด์šฉ์„ ๋‹ด์€ ๊ฐ•๋ ฅํ•œ ์ œ๋ชฉ
1049
  - ๋ถ€์ œ๋ชฉ: ํ—ค๋“œ๋ผ์ธ ๋ณด์™„ ์„ค๋ช…
1050
  - ๋ฆฌ๋“œ๋ฌธ: ๊ธฐ์‚ฌ์˜ ํ•ต์‹ฌ์„ ์š”์•ฝํ•œ ์ฒซ ๋ฌธ๋‹จ
1051
  - ๋ณธ๋ฌธ: ์ƒ์„ธ ๋‚ด์šฉ ์ „๊ฐœ
1052
+
1053
  2. ์ž‘์„ฑ ๊ทœ์น™
1054
  - ๊ฐ๊ด€์ ์ด๊ณ  ์ •ํ™•ํ•œ ์‚ฌ์‹ค ์ „๋‹ฌ
1055
  - ๋ฌธ์žฅ์€ '๋‹ค.'๋กœ ์ข…๊ฒฐ
 
1057
  - ์ธ์šฉ๊ตฌ๋Š” ๋”ฐ์˜ดํ‘œ ์ฒ˜๋ฆฌ
1058
  - ํ•ต์‹ฌ ์ •๋ณด๋ฅผ ์•ž๋ถ€๋ถ„์— ๋ฐฐ์น˜
1059
  - ์ „๋ฌธ ์šฉ์–ด๋Š” ์ ์ ˆํ•œ ์„ค๋ช… ์ถ”๊ฐ€
1060
+
1061
  3. ํ˜•์‹
1062
  - ์ ์ ˆํ•œ ๋‹จ๋ฝ ๊ตฌ๋ถ„
1063
  - ์ฝ๊ธฐ ์‰ฌ์šด ๋ฌธ์žฅ ๊ธธ์ด
1064
  - ๋…ผ๋ฆฌ์ ์ธ ์ •๋ณด ๊ตฌ์„ฑ
1065
+
1066
  ๊ฐ ๋‹จ๊ณ„๋Š” '===๋ฒˆ์—ญ===', '===๊ธฐ์‚ฌ==='๋กœ ๋ช…ํ™•ํžˆ ๊ตฌ๋ถ„ํ•˜์—ฌ ์ถœ๋ ฅํ•˜์„ธ์š”.
1067
  """
1068
 
 
1099
 
1100
  return history
1101
 
1102
+
1103
+ def continue_writing(history, system_message, max_tokens, temperature, top_p):
1104
+ if not history:
1105
+ return history
1106
+
1107
+ last_response = history[-1][1] if history else ""
1108
+ continue_prompt = f"""์ด์ „ ๋‚ด์šฉ์„ ์ด์–ด์„œ ๊ณ„์† ์ž‘์„ฑํ•ด์ฃผ์„ธ์š”.
1109
+ ๋งˆ์ง€๋ง‰ ์‘๋‹ต: {last_response}
1110
+
1111
+ ์ถ”๊ฐ€ ์ง€์นจ:
1112
+ 1. ์ด์ „ ๋‚ด์šฉ์˜ ๋งฅ๋ฝ์„ ์œ ์ง€ํ•˜๋ฉฐ ์ž์—ฐ์Šค๋Ÿฝ๊ฒŒ ์ด์–ด์„œ ์ž‘์„ฑ
1113
+ 2. ์ƒˆ๋กœ์šด ์ •๋ณด๋‚˜ ์ƒ์„ธ ์„ค๋ช…์„ ์ถ”๊ฐ€
1114
+ 3. ํ•„์š”ํ•œ ๊ฒฝ์šฐ ๋ณด์ถฉ ์„ค๋ช…์ด๋‚˜ ๋ถ„์„ ์ œ๊ณต
1115
+ 4. ๊ธฐ์‚ฌ ํ˜•์‹๊ณผ ์Šคํƒ€์ผ ์œ ์ง€
1116
+ 5. ํ•„์š”ํ•œ ๊ฒฝ์šฐ ์ถ”๊ฐ€์ ์ธ ์ด๋ฏธ์ง€ ํ”„๋กฌํ”„ํŠธ ์ƒ์„ฑ
1117
+ """
1118
+
1119
+ # ๋ฉ”์‹œ์ง€ ๊ตฌ์กฐ ์ˆ˜์ •
1120
+ messages = [
1121
+ {"role": "system", "content": system_message},
1122
+ {"role": "user", "content": continue_prompt} # ์‚ฌ์šฉ์ž ๋ฉ”์‹œ์ง€๋กœ ์‹œ์ž‘
1123
+ ]
1124
+
1125
+ try:
1126
+ full_response = ""
1127
+ for message in client.chat.completions.create(
1128
+ model="CohereForAI/c4ai-command-r-plus-08-2024",
1129
+ max_tokens=max_tokens,
1130
+ stream=True,
1131
+ temperature=temperature,
1132
+ top_p=top_p,
1133
+ messages=messages,
1134
+ ):
1135
+ if hasattr(message.choices[0].delta, 'content'):
1136
+ token = message.choices[0].delta.content
1137
+ if token:
1138
+ full_response += token
1139
+ # ์ด์ „ ๋Œ€ํ™” ๊ธฐ๋ก์„ ์œ ์ง€ํ•˜๋ฉด์„œ ์ƒˆ๋กœ์šด ์‘๋‹ต ์ถ”๊ฐ€
1140
+ new_history = history.copy()
1141
+ new_history.append(("๊ณ„์† ์ž‘์„ฑ", full_response))
1142
+ yield new_history
1143
+
1144
+ except Exception as e:
1145
+ error_message = f"๊ณ„์† ์ž‘์„ฑ ์ค‘ ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ–ˆ์Šต๋‹ˆ๋‹ค: {str(e)}"
1146
+ new_history = history.copy()
1147
+ new_history.append(("์˜ค๋ฅ˜", error_message))
1148
+ yield new_history
1149
+
1150
+ return history
1151
+
1152
  with gr.Blocks(theme="Yntec/HaleyCH_Theme_Orange", css=css, title="NewsAI ์„œ๋น„์Šค") as iface:
1153
+ init_db() # DB ์ดˆ๊ธฐํ™”
1154
+
1155
  with gr.Tabs():
1156
+ # DB ์ €์žฅ/๋ถˆ๋Ÿฌ์˜ค๊ธฐ ํƒญ
1157
+ with gr.Tab("DB ๊ฒ€์ƒ‰"):
1158
+ gr.Markdown("์‚ผ์„ฑ/๋ฏธ๊ตญ ๊ฒ€์ƒ‰ ๊ฒฐ๊ณผ๋ฅผ DB์— ์ €์žฅํ•˜๊ณ  ๋ถˆ๋Ÿฌ์˜ต๋‹ˆ๋‹ค.")
1159
+
1160
+ with gr.Row():
1161
+ search_button = gr.Button("๊ฒ€์ƒ‰: samsung/๋ฏธ๊ตญ", variant="primary")
1162
+ load_button = gr.Button("์ถœ๋ ฅ: samsung/๋ฏธ๊ตญ", variant="secondary")
1163
+
1164
+ results_display = gr.Markdown()
1165
+
1166
+ # ๋ฒ„ํŠผ ์ด๋ฒคํŠธ ์—ฐ๊ฒฐ
1167
+ search_button.click(
1168
+ fn=search_samsung_us,
1169
+ outputs=results_display
1170
+ )
1171
+
1172
+ load_button.click(
1173
+ fn=load_samsung_us,
1174
+ outputs=results_display
1175
+ )
1176
+
1177
  with gr.Tab("๊ตญ๊ฐ€๋ณ„"):
1178
  gr.Markdown("๊ฒ€์ƒ‰์–ด๋ฅผ ์ž…๋ ฅํ•˜๊ณ  ์›ํ•˜๋Š” ๊ตญ๊ฐ€(ํ•œ๊ตญ ์ œ์™ธ)๋ฅผ๋ฅผ ์„ ํƒํ•˜๋ฉด, ๊ฒ€์ƒ‰์–ด์™€ ์ผ์น˜ํ•˜๋Š” 24์‹œ๊ฐ„ ์ด๋‚ด ๋‰ด์Šค๋ฅผ ์ตœ๋Œ€ 100๊ฐœ ์ถœ๋ ฅํ•ฉ๋‹ˆ๋‹ค.")
1179
  gr.Markdown("๊ตญ๊ฐ€ ์„ ํƒํ›„ ๊ฒ€์ƒ‰์–ด์— 'ํ•œ๊ธ€'์„ ์ž…๋ ฅํ•˜๋ฉด ํ˜„์ง€ ์–ธ์–ด๋กœ ๋ฒˆ์—ญ๋˜์–ด ๊ฒ€์ƒ‰ํ•ฉ๋‹ˆ๋‹ค. ์˜ˆ: 'Taiwan' ๊ตญ๊ฐ€ ์„ ํƒํ›„ '์‚ผ์„ฑ' ์ž…๋ ฅ์‹œ 'ไธ‰ๆ˜Ÿ'์œผ๋กœ ์ž๋™ ๊ฒ€์ƒ‰")
 
1216
  translated_query_display = gr.Markdown(visible=False)
1217
  search_button = gr.Button("๊ฒ€์ƒ‰", variant="primary")
1218
 
 
1219
  progress = gr.Progress()
1220
  articles_state = gr.State([])
1221
 
 
1273
  'index': i,
1274
  })
1275
 
1276
+ # AI ๋ฒˆ์—ญ ํƒญ
 
1277
  with gr.Tab("AI ๊ธฐ์‚ฌ ์ƒ์„ฑ"):
1278
  gr.Markdown("๋‰ด์Šค URL์„ ์ž…๋ ฅํ•˜๋ฉด AI๊ฐ€ ํ•œ๊ตญ์–ด๋กœ ๋ฒˆ์—ญํ•˜์—ฌ ๊ธฐ์‚ฌ ํ˜•์‹์œผ๋กœ ์ž‘์„ฑํ•ฉ๋‹ˆ๋‹ค.")
1279
  gr.Markdown("์ด๋ฏธ์ง€ ์ƒ์„ฑ: https://huggingface.co/spaces/ginipick/FLUXllama ")
 
1287
  placeholder="https://..."
1288
  )
1289
 
1290
+ with gr.Row():
1291
+ translate_button = gr.Button("๊ธฐ์‚ฌ ์ƒ์„ฑ", variant="primary")
1292
+ continue_button = gr.Button("๊ณ„์† ์ด์–ด์„œ ์ž‘์„ฑ", variant="secondary")
1293
 
1294
+ with gr.Accordion("๊ณ ๊ธ‰ ์„ค์ •", open=False):
1295
  system_message = gr.Textbox(
1296
+ value="""You are a professional translator and journalist. Follow these steps strictly:
1297
  1. TRANSLATION
1298
  - Start with ===๋ฒˆ์—ญ=== marker
1299
  - Provide accurate Korean translation
 
1323
  - Clearly separate each section with markers
1324
  - Never skip or combine steps
1325
  - Ensure image prompts align with article content""",
1326
+ label="System message"
1327
+ )
1328
 
 
 
1329
  max_tokens = gr.Slider(
1330
  minimum=1,
1331
+ maximum=7800,
1332
  value=7624,
1333
  step=1,
1334
  label="Max new tokens"
 
1347
  step=0.05,
1348
  label="Top-P"
1349
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1350
 
 
1351
  # ์ด๋ฒคํŠธ ์—ฐ๊ฒฐ ๋ถ€๋ถ„
1352
  # ๊ตญ๊ฐ€๋ณ„ ํƒญ ์ด๋ฒคํŠธ
1353
  search_outputs = [status_message, translated_query_display, gr.Markdown(visible=False)]
 
1381
  show_progress=True
1382
  )
1383
 
1384
+ # AI ๋ฒˆ์—ญ ํƒญ ์ด๋ฒคํŠธ
1385
+ translate_button.click(
1386
+ fn=respond,
1387
+ inputs=[
1388
+ url_input,
1389
+ chatbot,
1390
+ system_message,
1391
+ max_tokens,
1392
+ temperature,
1393
+ top_p,
1394
+ ],
1395
+ outputs=chatbot
1396
+ )
1397
+
1398
+ # ๊ณ„์† ์ž‘์„ฑ ๋ฒ„ํŠผ ์ด๋ฒคํŠธ
1399
+ continue_button.click(
1400
+ fn=continue_writing,
1401
+ inputs=[
1402
+ chatbot,
1403
+ system_message,
1404
+ max_tokens,
1405
+ temperature,
1406
+ top_p,
1407
+ ],
1408
+ outputs=chatbot
1409
+ )
1410
+
1411
  iface.launch(
1412
  server_name="0.0.0.0",
1413
  server_port=7860,
 
1415
  auth=("gini","pick"),
1416
  ssl_verify=False,
1417
  show_error=True
1418
+ )