Update app.py
Browse files
app.py
CHANGED
@@ -146,20 +146,36 @@ def text_to_parquet(text: str) -> Tuple[str, str, str]:
|
|
146 |
|
147 |
def preprocess_text_with_llm(input_text: str) -> str:
|
148 |
# LLMμκ² μ
λ ₯ ν
μ€νΈλ₯Ό μ μ²λ¦¬νλλ‘ μμ²
|
149 |
-
system_prompt = """λΉμ μ μ
λ ₯λ κΈ΄ ν
μ€νΈλ₯Ό
|
150 |
-
|
151 |
-
-
|
152 |
-
-
|
153 |
-
-
|
154 |
-
-
|
155 |
-
-
|
156 |
-
-
|
157 |
-
|
158 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
159 |
try:
|
160 |
response = ""
|
161 |
stream = hf_client.text_generation(
|
162 |
-
prompt=
|
163 |
max_new_tokens=2000,
|
164 |
temperature=0.5,
|
165 |
top_p=0.9,
|
@@ -168,7 +184,8 @@ def preprocess_text_with_llm(input_text: str) -> str:
|
|
168 |
for msg in stream:
|
169 |
if msg:
|
170 |
response += msg
|
171 |
-
#
|
|
|
172 |
processed_text = response.strip()
|
173 |
return processed_text
|
174 |
except Exception as e:
|
@@ -176,6 +193,7 @@ def preprocess_text_with_llm(input_text: str) -> str:
|
|
176 |
print(error_message)
|
177 |
return error_message
|
178 |
|
|
|
179 |
# CSS μ€μ
|
180 |
css = """
|
181 |
footer {
|
@@ -262,15 +280,7 @@ with gr.Blocks(css=css) as demo:
|
|
262 |
|
263 |
send_data_upload.click(
|
264 |
handle_message_data_upload,
|
265 |
-
inputs=[
|
266 |
-
msg_data_upload,
|
267 |
-
chatbot_data_upload,
|
268 |
-
system_message,
|
269 |
-
max_tokens,
|
270 |
-
temperature,
|
271 |
-
top_p,
|
272 |
-
parquet_data_state, # parquet_data_stateλ₯Ό μ¬μ©νμ¬ μ
λ‘λλ λ°μ΄ν°λ₯Ό μ λ¬
|
273 |
-
],
|
274 |
outputs=[chatbot_data_upload, msg_data_upload],
|
275 |
queue=True
|
276 |
)
|
@@ -406,3 +416,5 @@ if __name__ == "__main__":
|
|
406 |
|
407 |
|
408 |
|
|
|
|
|
|
146 |
|
147 |
def preprocess_text_with_llm(input_text: str) -> str:
|
148 |
# LLMμκ² μ
λ ₯ ν
μ€νΈλ₯Ό μ μ²λ¦¬νλλ‘ μμ²
|
149 |
+
system_prompt = """λΉμ μ λ°μ΄ν° μ μ²λ¦¬ μ λ¬Έκ°μ
λλ€. μ
λ ₯λ κΈ΄ ν
μ€νΈλ₯Ό μλμ κ°μ λ°μ΄ν°μ
νμμΌλ‘ μ μ²λ¦¬νμΈμ:
|
150 |
+
|
151 |
+
- **λ°μ΄ν°μ
νμ:** `id,text,label,metadata`
|
152 |
+
- **κ° νμ μλ‘μ΄ μ€λ‘ ꡬλΆλκ³ **, νλλ μΌνλ‘ κ΅¬λΆλ©λλ€.
|
153 |
+
- **ν
μ€νΈλ λ€λ₯Έ νλ λ΄μ μΌνκ° μμ κ²½μ°**, ν΄λΉ νλλ₯Ό ν°λ°μ΄ν(")λ‘ κ°μΈμΈμ.
|
154 |
+
- **νλ λ΄μ ν°λ°μ΄νκ° μμ κ²½μ°**, λ°±μ¬λμ(\\)λ‘ μ΄μ€μΌμ΄ν μ²λ¦¬νμΈμ. μ: \\"
|
155 |
+
- ν
μ€νΈλ₯Ό **μλ―Έ λ¨μλ‘ λΆν **νκ³ , κ° λ¬Έμ₯μ λν΄ **1λΆν° μμνλ μ°μλ id**λ₯Ό λΆμ¬νμΈμ.
|
156 |
+
- κ° λ¬Έμ₯μ λν΄ **μ μ ν label(μΉ΄ν
κ³ λ¦¬)**μ μ§μ νμΈμ. μ: "κΈ°μ ", "μ¬ν", "κ²½μ "
|
157 |
+
- **metadata**μλ μΆμ²λ λ μ§ λ±μ μΆκ° μ 보λ₯Ό ν¬ν¨νμΈμ.
|
158 |
+
- μ΅μ’
κ²°κ³Όλ **κ° νμ΄ `id,text,label,metadata` νμμ CSV**κ° λλλ‘ νμΈμ.
|
159 |
+
|
160 |
+
**μμ:**
|
161 |
+
|
162 |
+
μ
λ ₯ ν
μ€νΈ:
|
163 |
+
|
164 |
+
"μ€λμ λ μ¨κ° μ’λ€. λ΄μΌμ λΉκ° μ¬ μμ μ΄λ€."
|
165 |
+
|
166 |
+
μ μ²λ¦¬λ λ°μ΄ν°μ
:
|
167 |
+
1,"μ€λμ λ μ¨κ° μ’λ€.","λ μ¨","2023-10-05"
|
168 |
+
2,"λ΄μΌμ λΉκ° μ¬ μμ μ΄λ€.","λ μ¨","2023-10-05"
|
169 |
+
|
170 |
+
**μ΄μ μλμ μ
λ ₯ ν
μ€νΈλ₯Ό μ²λ¦¬νμΈμ:**
|
171 |
+
|
172 |
+
""" + input_text
|
173 |
+
|
174 |
+
# LLM νΈμΆ λ° μλ΅ μ²λ¦¬
|
175 |
try:
|
176 |
response = ""
|
177 |
stream = hf_client.text_generation(
|
178 |
+
prompt=system_prompt,
|
179 |
max_new_tokens=2000,
|
180 |
temperature=0.5,
|
181 |
top_p=0.9,
|
|
|
184 |
for msg in stream:
|
185 |
if msg:
|
186 |
response += msg
|
187 |
+
# λλ²κΉ
: LLMμ μλ΅ μΆλ ₯
|
188 |
+
print("LLM μλ΅:\n", response)
|
189 |
processed_text = response.strip()
|
190 |
return processed_text
|
191 |
except Exception as e:
|
|
|
193 |
print(error_message)
|
194 |
return error_message
|
195 |
|
196 |
+
|
197 |
# CSS μ€μ
|
198 |
css = """
|
199 |
footer {
|
|
|
280 |
|
281 |
send_data_upload.click(
|
282 |
handle_message_data_upload,
|
283 |
+
inputs=[ msg_data_upload, chatbot_data_upload, system_message, max_tokens, temperature, top_p, parquet_data_state, # parquet_data_stateλ₯Ό μ¬μ©νμ¬ μ
λ‘λλ λ°μ΄ν°λ₯Ό μ λ¬ ],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
284 |
outputs=[chatbot_data_upload, msg_data_upload],
|
285 |
queue=True
|
286 |
)
|
|
|
416 |
|
417 |
|
418 |
|
419 |
+
|
420 |
+
|