Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,14 +1,29 @@
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
3 |
|
4 |
-
#
|
5 |
-
generator = pipeline("text-generation", model="bigscience/bloomz-560m")
|
6 |
|
7 |
# μλ΅ μμ± ν¨μ
|
8 |
def generate_reply(review):
|
|
|
9 |
prompt = f"κ³ κ° λ¦¬λ·°: \"{review}\" μ΄ λ¦¬λ·°μ λν΄ μ μ€νκ³ κ°μ¬μ λ»μ λ΄μ λ΅λ³μ μμ±νμΈμ."
|
10 |
-
|
11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
|
13 |
# Gradio μΈν°νμ΄μ€ μ€μ
|
14 |
iface = gr.Interface(
|
@@ -16,7 +31,7 @@ iface = gr.Interface(
|
|
16 |
inputs="text",
|
17 |
outputs="text",
|
18 |
title="Review Reply Generator",
|
19 |
-
description="κ³ κ° λ¦¬λ·°λ₯Ό μ
λ ₯νλ©΄
|
20 |
)
|
21 |
|
22 |
# Space μ€ν
|
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
3 |
|
4 |
+
# λͺ¨λΈ λ‘λ
|
5 |
+
generator = pipeline("text-generation", model="bigscience/bloomz-560m") # λͺ¨λΈ μ΄λ¦μ μ μ ν λ³κ²½νμΈμ.
|
6 |
|
7 |
# μλ΅ μμ± ν¨μ
|
8 |
def generate_reply(review):
|
9 |
+
# ν둬ννΈ μμ±
|
10 |
prompt = f"κ³ κ° λ¦¬λ·°: \"{review}\" μ΄ λ¦¬λ·°μ λν΄ μ μ€νκ³ κ°μ¬μ λ»μ λ΄μ λ΅λ³μ μμ±νμΈμ."
|
11 |
+
|
12 |
+
try:
|
13 |
+
# λͺ¨λΈμ ν둬ννΈ μ λ¬
|
14 |
+
result = generator(prompt, max_length=100, do_sample=True, temperature=0.7)
|
15 |
+
|
16 |
+
# μμ±λ ν
μ€νΈ λ°ν
|
17 |
+
generated_text = result[0]["generated_text"]
|
18 |
+
|
19 |
+
# λͺ¨λΈμ΄ ν둬ννΈκΉμ§ ν¬ν¨νμ¬ μλ΅νλ κ²½μ°λ₯Ό μ²λ¦¬
|
20 |
+
if prompt in generated_text:
|
21 |
+
generated_text = generated_text.replace(prompt, "").strip()
|
22 |
+
|
23 |
+
return generated_text
|
24 |
+
|
25 |
+
except Exception as e:
|
26 |
+
return f"μ€λ₯κ° λ°μνμ΅λλ€: {str(e)}"
|
27 |
|
28 |
# Gradio μΈν°νμ΄μ€ μ€μ
|
29 |
iface = gr.Interface(
|
|
|
31 |
inputs="text",
|
32 |
outputs="text",
|
33 |
title="Review Reply Generator",
|
34 |
+
description="κ³ κ° λ¦¬λ·°λ₯Ό μ
λ ₯νλ©΄ μ μ€νκ³ κ°μ¬μ λ»μ λ΄μ λ΅λ³μ μμ±ν©λλ€."
|
35 |
)
|
36 |
|
37 |
# Space μ€ν
|