seawolf2357 commited on
Commit
f7f4bea
ยท
verified ยท
1 Parent(s): 25abb2d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -39
app.py CHANGED
@@ -1,44 +1,40 @@
1
  import gradio as gr
2
- import imageio
3
- import numpy as np
4
- from PIL import Image
5
 
6
- def resize_image(image, target_width, target_height):
7
- """
8
- ์ด๋ฏธ์ง€๋ฅผ ์ง€์ •๋œ ํฌ๊ธฐ๋กœ ์กฐ์ •ํ•ฉ๋‹ˆ๋‹ค.
9
- """
10
- image_pil = Image.fromarray(image).resize((target_width, target_height), Image.ANTIALIAS)
11
- return np.array(image_pil)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
 
13
- def create_video(images):
14
- """
15
- ์ฃผ์–ด์ง„ ์ด๋ฏธ์ง€ ๋ฆฌ์ŠคํŠธ๋กœ๋ถ€ํ„ฐ ๋น„๋””์˜ค๋ฅผ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.
16
- ๋ชจ๋“  ์ด๋ฏธ์ง€๋Š” ๋น„๋””์˜ค์— ์ถ”๊ฐ€๋˜๊ธฐ ์ „์— ๋™์ผํ•œ ํฌ๊ธฐ๋กœ ์กฐ์ •๋ฉ๋‹ˆ๋‹ค.
17
- """
18
- target_width = 1920
19
- target_height = 1080
20
- with imageio.get_writer('output_video.mp4', fps=2) as video:
21
- for img in images:
22
- img_resized = resize_image(img, target_width, target_height)
23
- video.append_data(img_resized)
24
- return 'output_video.mp4'
25
-
26
- def process_images(image_files):
27
- """
28
- ์—…๋กœ๋“œ๋œ ์ด๋ฏธ์ง€ ํŒŒ์ผ๋“ค์„ ์ฒ˜๋ฆฌํ•˜์—ฌ ๋น„๋””์˜ค๋ฅผ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.
29
- """
30
- images = [imageio.v3.imread(image_file) for image_file in image_files]
31
- video_file = create_video(images)
32
- return video_file
33
-
34
- # Gradio ์ธํ„ฐํŽ˜์ด์Šค ์ •์˜
35
- iface = gr.Interface(
36
- fn=process_images,
37
- inputs=gr.File(label="Upload Images", type="file", multiple_files=True), # ์ˆ˜์ •๋œ ๋ถ€๋ถ„
38
- outputs="file",
39
- title="Image to Video Converter",
40
- description="Upload multiple images to create a video."
41
- )
42
 
43
  # Gradio ์•ฑ ์‹คํ–‰
44
- iface.launch()
 
1
  import gradio as gr
2
+ import requests
 
 
3
 
4
+ def get_lunar_info(year, month, day, time):
5
+ # API URL ์„ค์ •
6
+ url = "https://api.example.com/get_lunar_info"
7
+
8
+ # API์— ์ „๋‹ฌํ•  ๋ฐ์ดํ„ฐ ์„ค์ •
9
+ data = {
10
+ "year": year,
11
+ "month": month,
12
+ "day": day,
13
+ "time": time
14
+ }
15
+
16
+ # API ํ˜ธ์ถœ
17
+ response = requests.post(url, json=data)
18
+
19
+ # API ์‘๋‹ต ํ™•์ธ ๋ฐ ๊ฒฐ๊ณผ ๋ฐ˜ํ™˜
20
+ if response.status_code == 200:
21
+ return response.json()
22
+ else:
23
+ return "API ํ˜ธ์ถœ์— ์‹คํŒจํ–ˆ์Šต๋‹ˆ๋‹ค."
24
 
25
+ # Gradio ์ธํ„ฐํŽ˜์ด์Šค ๊ตฌ์„ฑ
26
+ with gr.Blocks() as demo:
27
+ gr.Markdown("### ์ƒ๋…„์›”์ผ ๋ฐ ์ƒ์‹œ ์ •๋ณด ์ž…๋ ฅ")
28
+ year = gr.Textbox(label="์ƒ๋…„(์˜ˆ: 1990)")
29
+ month = gr.Textbox(label="์ƒ์›”(์˜ˆ: 01)")
30
+ day = gr.Textbox(label="์ƒ์ผ(์˜ˆ: 31)")
31
+ time = gr.Textbox(label="์ƒ์‹œ(์˜ˆ์‹œ: 1030)")
32
+
33
+ submit_button = gr.Button("์ •๋ณด ์ œ์ถœ")
34
+
35
+ result = gr.Textbox(label="๊ฒฐ๊ณผ")
36
+
37
+ submit_button.click(fn=get_lunar_info, inputs=[year, month, day, time], outputs=result)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
38
 
39
  # Gradio ์•ฑ ์‹คํ–‰
40
+ demo.launch()