Spaces:
Sleeping
Sleeping
File size: 3,935 Bytes
95f8d1c 90790c1 95f8d1c 2cc4827 95f8d1c |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
import os, json, requests
import gradio as gr
from dotenv import load_dotenv
# ํ๊ฒฝ ๋ณ์ ๋ก๋
load_dotenv(os.path.join(os.path.dirname(__file__), "..", "backend", ".env"), override=True)
BACKEND = os.getenv('BACKEND_URL','http://localhost:9000')
with gr.Blocks(title='PersonaMate Pro (OAuth + Simplified UI)') as demo:
gr.Markdown('## PersonaMate Pro โ OAuth ์์ง + ์ถ์ฒ UI')
with gr.Row():
with gr.Column(scale=1):
gr.Markdown('### 1) OAuth ๋ก๊ทธ์ธ')
google_html = gr.HTML(f'<a href="{BACKEND}/oauth/google/start" target="_blank">Google (YouTube) ๋ก๊ทธ์ธ ์ด๊ธฐ</a>')
instagram_html = gr.HTML(f'<a href="{BACKEND}/oauth/instagram/start" target="_blank">Instagram ๋ก๊ทธ์ธ ์ด๊ธฐ</a>')
x_html = gr.HTML(f'<a href="{BACKEND}/oauth/x/start" target="_blank">X (Twitter) ๋ก๊ทธ์ธ ์ด๊ธฐ</a>')
with gr.Column(scale=2):
gr.Markdown('### 2) ์๋ ์์ง')
yt_chk=gr.Checkbox(label='YouTube ๊ตฌ๋
๋ชฉ๋ก ์ฌ์ฉ', value=True)
ig_chk=gr.Checkbox(label='Instagram ํด์ํ๊ทธ ์ฌ์ฉ', value=False)
x_chk=gr.Checkbox(label='X ํ๋ก์ ์ฌ์ฉ์๋ช
์ฌ์ฉ', value=False)
fetch_btn=gr.Button('๋ด ๊ณ์ ์์ ๋ฐ์ดํฐ ์์ง')
fetch_result=gr.JSON(label="์์ง๋ ๋ฐ์ดํฐ ๋ฏธ๋ฆฌ๋ณด๊ธฐ")
with gr.Row():
with gr.Column(scale=1):
gr.Markdown('### 3) ์
๋ ฅ/MBTI')
yt_text=gr.Textbox(lines=6,label='์ ํ๋ธ ๊ตฌ๋
(์์ง/์๋ ํผ์ฉ)')
sns_text=gr.Textbox(lines=6,label='SNS ํค์๋/๊ณ์ (์์ง/์๋ ํผ์ฉ)')
mbti=gr.Dropdown(choices=['ISTJ','ISFJ','INFJ','INTJ','ISTP','ISFP','INFP','INTP','ESTP','ESFP','ENFP','ENTP','ESTJ','ESFJ','ENFJ','ENTJ'], value='ENFP', label='MBTI')
use_openai=gr.Checkbox(label='OpenAI ์๋ฒ ๋ฉ ์ฌ์ฉ', value=True)
run_btn=gr.Button('๋ถ์ & ์ถ์ฒ ์คํ', variant='primary')
send_email_btn=gr.Button("์ถ์ฒ ๊ฒฐ๊ณผ ์ด๋ฉ์ผ๋ก ๋ณด๋ด๊ธฐ (Gmail)")
with gr.Column(scale=3):
gr.Markdown('### 4) ์ถ์ฒ ๊ฒฐ๊ณผ')
result_table=gr.Dataframe(headers=["์ฑ๋ ์ด๋ฆ","์ฌ์ดํธ ์ฃผ์"], row_count=10, col_count=2)
# ๋ฒํผ ๋์ ์ฐ๊ฒฐ ์ ๊ฑฐ (Hugging Face์์๋ webbrowser.open ์ฌ์ฉ ๋ถ๊ฐ)
# ๋์ gr.Link ์ปดํฌ๋ํธ๋ก ๋์ฒด
def fetch_data_fn():
try:
res = requests.get(f"{BACKEND}/fetch_data", timeout=60)
res.raise_for_status()
return res.json()
except Exception as e:
return {"error": str(e)}
fetch_btn.click(fetch_data_fn, inputs=[], outputs=[fetch_result])
def _run(yt, sns, mbti, use_openai):
try:
payload = {
"youtube_subscriptions": [s.strip() for s in yt.splitlines() if s.strip()],
"sns_keywords": [s.strip() for s in sns.splitlines() if s.strip()],
"mbti": mbti
}
res = requests.post(f"{BACKEND}/youtube/recommendations", json=payload, timeout=120)
res.raise_for_status()
data = res.json().get("recommendations", {})
except Exception as e:
data = {"youtube":[{"name":"์ถ์ฒ ์คํจ","url":str(e)}], "web":[]}
rows = []
youtube_list = data.get("youtube", [])
web_list = data.get("web", [])
if not youtube_list and not web_list:
# fallback: ์ต์ํ 1๊ฐ๋ผ๋ ํ์
youtube_list = [{"name":"์ถ์ฒ ์คํจ","url":"http://youtube.com"}]
web_list = [{"name":"์ถ์ฒ ์คํจ","url":"http://example.com"}]
for c in youtube_list + web_list:
rows.append([
c.get("name",""),
c.get("url","")
])
return rows
run_btn.click(_run, [yt_text, sns_text, mbti, use_openai], [result_table])
if __name__=='__main__':
demo.launch()
|