Sunghokim commited on
Commit
1389ddb
โ€ข
1 Parent(s): 94a81d2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -20
app.py CHANGED
@@ -1,27 +1,25 @@
 
 
1
  import gradio as gr
2
- from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
3
 
4
- # ์˜์–ด-ํ•œ๊ตญ์–ด ๋ฒˆ์—ญ ๋ชจ๋ธ ๋กœ๋“œ
5
- model_name = "t5-base"
6
- model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
7
- tokenizer = AutoTokenizer.from_pretrained(model_name)
8
 
9
- def translate_text(input_text):
10
- # ์ž…๋ ฅ ํ…์ŠคํŠธ ํ† ํฐํ™”
11
- input_ids = tokenizer.encode(input_text, return_tensors="pt")
12
- # ๋ฒˆ์—ญ ๋ชจ๋ธ ์‹คํ–‰
13
- output = model.generate(input_ids, max_length=50)
14
- # ์ถœ๋ ฅ ํ…์ŠคํŠธ ์ƒ์„ฑ
15
- output_text = tokenizer.decode(output[0], skip_special_tokens=True)
16
- return output_text
17
 
18
- # Gradio ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๊ตฌ์ถ•
19
  iface = gr.Interface(
20
- fn=translate_text,
21
- inputs="text",
22
- outputs="text",
23
- title="English-Korean Translator",
24
- description="Enter English text to translate to Korean."
25
  )
26
 
27
- iface.launch()
 
 
 
1
+ # app.py
2
+
3
  import gradio as gr
4
+ from transformers import pipeline
5
 
6
+ # ๋ชจ๋ธ ๋กœ๋“œ
7
+ generator = pipeline('text-to-image', model='CompVis/stable-diffusion-v1-4')
 
 
8
 
9
+ def generate_image(prompt):
10
+ # ์ด๋ฏธ์ง€ ์ƒ์„ฑ
11
+ images = generator(prompt, num_return_sequences=1)
12
+ return images[0]['generated_image']
 
 
 
 
13
 
14
+ # Gradio ์ธํ„ฐํŽ˜์ด์Šค ์„ค์ •
15
  iface = gr.Interface(
16
+ fn=generate_image,
17
+ inputs=gr.inputs.Textbox(lines=2, placeholder="ํ…์ŠคํŠธ๋ฅผ ์ž…๋ ฅํ•˜์„ธ์š”..."),
18
+ outputs="image",
19
+ title="ํ…์ŠคํŠธ์—์„œ ์ด๋ฏธ์ง€ ์ƒ์„ฑ",
20
+ description="ํ…์ŠคํŠธ๋ฅผ ์ž…๋ ฅํ•˜๋ฉด ํ•ด๋‹น ํ…์ŠคํŠธ๋ฅผ ๊ธฐ๋ฐ˜์œผ๋กœ ์ด๋ฏธ์ง€๋ฅผ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค."
21
  )
22
 
23
+ # ์ธํ„ฐํŽ˜์ด์Šค ์‹คํ–‰
24
+ if __name__ == "__main__":
25
+ iface.launch()