Kims12 commited on
Commit
c777df6
ยท
verified ยท
1 Parent(s): 121b238

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +72 -59
app.py CHANGED
@@ -1,9 +1,8 @@
1
- # app.py
2
  import gradio as gr
3
  import openai
4
  import os
5
  from typing import Optional
6
- from gradio_client import Client # gradio_client ์ถ”๊ฐ€
7
 
8
  #############################
9
 
@@ -75,25 +74,9 @@ OPENAI_TEMPERATURE = 0.7
75
  OPENAI_TOP_P = 0.95
76
 
77
  #############################
78
- # API ํด๋ผ์ด์–ธํŠธ ์„ค์ •
79
  #############################
80
- # ์™ธ๋ถ€ Space์˜ API ํด๋ผ์ด์–ธํŠธ ์„ค์ •
81
- API_CLIENT = Client("Kims12/blog")
82
-
83
- def fetch_blog_content(url: str) -> str:
84
- """
85
- ์ฃผ์–ด์ง„ URL์„ ์ด์šฉํ•ด ๋ธ”๋กœ๊ทธ ๋ณธ๋ฌธ์„ ๊ฐ€์ ธ์˜ค๋Š” ํ•จ์ˆ˜.
86
- """
87
- if not url.strip():
88
- return "URL์„ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”."
89
- try:
90
- result = API_CLIENT.predict(
91
- url=url,
92
- api_name="/predict"
93
- )
94
- return result
95
- except Exception as e:
96
- return f"API ํ˜ธ์ถœ ์ค‘ ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ–ˆ์Šต๋‹ˆ๋‹ค: {str(e)}"
97
 
98
  #############################
99
  # UI - ๋ธ”๋กœ๊ทธ ์ƒ์„ฑ๊ธฐ
@@ -108,19 +91,79 @@ with gr.Blocks() as demo:
108
  value="์ผ๋ฐ˜์ ์ธ" # ๊ธฐ๋ณธ ์„ ํƒ
109
  )
110
 
111
- # ์ฐธ์กฐ๊ธ€ ์ž…๋ ฅ (3๊ฐœ) ๋ฐ API ์‹คํ–‰ ๋ฒ„ํŠผ
112
  with gr.Row():
113
- ref1 = gr.Textbox(label="์ฐธ์กฐ๊ธ€ 1 (URL ์ž…๋ ฅ)")
114
- fetch1 = gr.Button("์ฐธ์กฐ๊ธ€1 API ์‹คํ–‰")
115
- with gr.Row():
116
- ref2 = gr.Textbox(label="์ฐธ์กฐ๊ธ€ 2 (URL ์ž…๋ ฅ)")
117
- fetch2 = gr.Button("์ฐธ์กฐ๊ธ€2 API ์‹คํ–‰")
118
- with gr.Row():
119
- ref3 = gr.Textbox(label="์ฐธ์กฐ๊ธ€ 3 (URL ์ž…๋ ฅ)")
120
- fetch3 = gr.Button("์ฐธ์กฐ๊ธ€3 API ์‹คํ–‰")
 
121
 
122
  output_box = gr.Textbox(label="๊ฒฐ๊ณผ", lines=20, interactive=False)
123
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
124
  def generate_blog(tone_value: str, ref1_value: str, ref2_value: str, ref3_value: str) -> str:
125
  # ํ”„๋กฌํ”„ํŠธ ์ƒ์„ฑ
126
  question = (
@@ -147,35 +190,5 @@ with gr.Blocks() as demo:
147
  outputs=output_box
148
  )
149
 
150
- # ์ฐธ์กฐ๊ธ€1 API ์‹คํ–‰
151
- def fetch_ref1(url: str) -> str:
152
- return fetch_blog_content(url)
153
-
154
- fetch1.click(
155
- fn=fetch_ref1,
156
- inputs=ref1,
157
- outputs=ref1
158
- )
159
-
160
- # ์ฐธ์กฐ๊ธ€2 API ์‹คํ–‰
161
- def fetch_ref2(url: str) -> str:
162
- return fetch_blog_content(url)
163
-
164
- fetch2.click(
165
- fn=fetch_ref2,
166
- inputs=ref2,
167
- outputs=ref2
168
- )
169
-
170
- # ์ฐธ์กฐ๊ธ€3 API ์‹คํ–‰
171
- def fetch_ref3(url: str) -> str:
172
- return fetch_blog_content(url)
173
-
174
- fetch3.click(
175
- fn=fetch_ref3,
176
- inputs=ref3,
177
- outputs=ref3
178
- )
179
-
180
  if __name__ == "__main__":
181
  demo.launch()
 
 
1
  import gradio as gr
2
  import openai
3
  import os
4
  from typing import Optional
5
+ from gradio_client import Client
6
 
7
  #############################
8
 
 
74
  OPENAI_TOP_P = 0.95
75
 
76
  #############################
77
+ # API ํด๋ผ์ด์–ธํŠธ ์„ค์ • (ํ—ˆ๊น…ํŽ˜์ด์Šค ์ŠคํŽ˜์ด์Šค)
78
  #############################
79
+ client = Client("Kims12/blog")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
80
 
81
  #############################
82
  # UI - ๋ธ”๋กœ๊ทธ ์ƒ์„ฑ๊ธฐ
 
91
  value="์ผ๋ฐ˜์ ์ธ" # ๊ธฐ๋ณธ ์„ ํƒ
92
  )
93
 
94
+ # ์ฐธ์กฐ๊ธ€ ์ž…๋ ฅ (3๊ฐœ)๊ณผ API ์‹คํ–‰ ๋ฒ„ํŠผ
95
  with gr.Row():
96
+ with gr.Column():
97
+ ref1 = gr.Textbox(label="์ฐธ์กฐ๊ธ€ 1")
98
+ fetch_button1 = gr.Button("API ์‹คํ–‰1")
99
+ with gr.Column():
100
+ ref2 = gr.Textbox(label="์ฐธ์กฐ๊ธ€ 2")
101
+ fetch_button2 = gr.Button("API ์‹คํ–‰2")
102
+ with gr.Column():
103
+ ref3 = gr.Textbox(label="์ฐธ์กฐ๊ธ€ 3")
104
+ fetch_button3 = gr.Button("API ์‹คํ–‰3")
105
 
106
  output_box = gr.Textbox(label="๊ฒฐ๊ณผ", lines=20, interactive=False)
107
 
108
+ # ์ฐธ์กฐ๊ธ€1 API ์‹คํ–‰ ํ•จ์ˆ˜
109
+ def fetch_ref1(url: str) -> str:
110
+ if not url:
111
+ return "URL์„ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”."
112
+ try:
113
+ result = client.predict(
114
+ url=url,
115
+ api_name="/predict"
116
+ )
117
+ return result
118
+ except Exception as e:
119
+ return f"์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ–ˆ์Šต๋‹ˆ๋‹ค: {str(e)}"
120
+
121
+ # ์ฐธ์กฐ๊ธ€2 API ์‹คํ–‰ ํ•จ์ˆ˜
122
+ def fetch_ref2(url: str) -> str:
123
+ if not url:
124
+ return "URL์„ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”."
125
+ try:
126
+ result = client.predict(
127
+ url=url,
128
+ api_name="/predict"
129
+ )
130
+ return result
131
+ except Exception as e:
132
+ return f"์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ–ˆ์Šต๋‹ˆ๋‹ค: {str(e)}"
133
+
134
+ # ์ฐธ์กฐ๊ธ€3 API ์‹คํ–‰ ํ•จ์ˆ˜
135
+ def fetch_ref3(url: str) -> str:
136
+ if not url:
137
+ return "URL์„ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”."
138
+ try:
139
+ result = client.predict(
140
+ url=url,
141
+ api_name="/predict"
142
+ )
143
+ return result
144
+ except Exception as e:
145
+ return f"์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ–ˆ์Šต๋‹ˆ๋‹ค: {str(e)}"
146
+
147
+ # ๋ฒ„ํŠผ ํด๋ฆญ ์‹œ ํ•ด๋‹น ์ฐธ์กฐ๊ธ€ API ์‹คํ–‰
148
+ fetch_button1.click(
149
+ fn=fetch_ref1,
150
+ inputs=ref1,
151
+ outputs=ref1
152
+ )
153
+
154
+ fetch_button2.click(
155
+ fn=fetch_ref2,
156
+ inputs=ref2,
157
+ outputs=ref2
158
+ )
159
+
160
+ fetch_button3.click(
161
+ fn=fetch_ref3,
162
+ inputs=ref3,
163
+ outputs=ref3
164
+ )
165
+
166
+ # ๋ธ”๋กœ๊ทธ ์ƒ์„ฑ ํ•จ์ˆ˜
167
  def generate_blog(tone_value: str, ref1_value: str, ref2_value: str, ref3_value: str) -> str:
168
  # ํ”„๋กฌํ”„ํŠธ ์ƒ์„ฑ
169
  question = (
 
190
  outputs=output_box
191
  )
192
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
193
  if __name__ == "__main__":
194
  demo.launch()