Update app.py
Browse files
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
|
| 7 |
|
| 8 |
#############################
|
| 9 |
|
|
@@ -75,25 +74,9 @@ OPENAI_TEMPERATURE = 0.7
|
|
| 75 |
OPENAI_TOP_P = 0.95
|
| 76 |
|
| 77 |
#############################
|
| 78 |
-
# API ํด๋ผ์ด์ธํธ ์ค์
|
| 79 |
#############################
|
| 80 |
-
|
| 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๊ฐ)
|
| 112 |
with gr.Row():
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
|
|
|
| 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()
|