HOJOON23 commited on
Commit
885048d
Β·
verified Β·
1 Parent(s): 7909461

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -5
app.py CHANGED
@@ -1,14 +1,29 @@
1
  import gradio as gr
2
  from transformers import pipeline
3
 
4
- # Hugging Face λͺ¨λΈ λ‘œλ“œ
5
- generator = pipeline("text-generation", model="bigscience/bloomz-560m")
6
 
7
  # 응닡 생성 ν•¨μˆ˜
8
  def generate_reply(review):
 
9
  prompt = f"고객 리뷰: \"{review}\" 이 리뷰에 λŒ€ν•΄ μ •μ€‘ν•˜κ³  κ°μ‚¬μ˜ λœ»μ„ 담은 닡변을 μž‘μ„±ν•˜μ„Έμš”."
10
- result = generator(prompt, max_length=100, do_sample=True, temperature=0.7)
11
- return result[0]["generated_text"]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 μ‹€ν–‰