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()
|