Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -12,13 +12,6 @@ import uuid
|
|
| 12 |
import base64
|
| 13 |
import requests
|
| 14 |
|
| 15 |
-
from pptx import Presentation
|
| 16 |
-
from pptx.util import Pt
|
| 17 |
-
import datetime
|
| 18 |
-
import requests
|
| 19 |
-
from pptx.util import Inches
|
| 20 |
-
from pathlib import Path
|
| 21 |
-
|
| 22 |
load_dotenv(verbose=True)
|
| 23 |
|
| 24 |
# Initialize Qdrant and Cohere clients
|
|
@@ -42,254 +35,6 @@ oauth_profile = OAuthProfile(
|
|
| 42 |
picture=""
|
| 43 |
)'''
|
| 44 |
|
| 45 |
-
def create_metapptx(file_name,key):
|
| 46 |
-
'''meta = {
|
| 47 |
-
"main_title":"AIエージェントについて",
|
| 48 |
-
"mokuji1":"AIエージェントの概要",
|
| 49 |
-
"mokuji2":"主な特徴",
|
| 50 |
-
"mokuji3":"仕組みと応用例",
|
| 51 |
-
"mokuji4":"課題と展望",
|
| 52 |
-
"p3_title":"AIエージェントの概要",
|
| 53 |
-
"p3_body":"AIエージェントは、人間のように自律的に行動し、特定の目標を達成するために設計された高度なAIシステムです。これらのエージェントは、環境から情報を取得し、意思決定を行い、行動を実行する能力を持っています。その結果、複雑なタスクを自動化し、効果的な解決策を提供できます。",
|
| 54 |
-
"p4_title":"主な特徴",
|
| 55 |
-
"p4_body1":"自律性: エージェントは自ら判断を行い、与えられたタスクを進めます。",
|
| 56 |
-
"p4_body2":"適応性: 環境の変化に応じて行動を調整し、新しい状況に適応します。",
|
| 57 |
-
"p4_body3":"連携能力: 複数のエージェントが協力してタスクを実行し、より複雑な問題に対応します。",
|
| 58 |
-
"p5_title":"応用例",
|
| 59 |
-
"p5_body1":"バーチャルアシスタント: 自然言語処理を活用してカスタマーサポートやスケジュール管理を支援。",
|
| 60 |
-
"p5_body2":"自動運転: 車両が周囲の状況を検出し、安全なルートを計画。",
|
| 61 |
-
"p5_body3":"医療分野: 症状を分析し、診断をサポート。",
|
| 62 |
-
"p6_title":"課題と展望",
|
| 63 |
-
"p6_body":"Issues & Prospect",
|
| 64 |
-
"p6_para1":"課題:・プライバシー問題や倫理的懸念。・誤った判断によるリスク。",
|
| 65 |
-
"p6_para2":"展望:・生成AIと統合することで、より高度な機能を実現。・新しい産業への適用範囲の拡大。"
|
| 66 |
-
}'''
|
| 67 |
-
|
| 68 |
-
url = f"https://www.ryhintl.com/dbjson/getjson?sqlcmd=select * from ku_keyslides where main_title = '"+key+"'"
|
| 69 |
-
response = requests.get(url)
|
| 70 |
-
|
| 71 |
-
mydata = response.content.decode("utf-8")
|
| 72 |
-
result = mydata.replace("[", "").replace("]", "")
|
| 73 |
-
|
| 74 |
-
meta = eval(result)
|
| 75 |
-
|
| 76 |
-
now = datetime.datetime.now() # 現在時刻の取得
|
| 77 |
-
today = now.strftime('%Y年%m月%d日') # 現在時刻を年月曜日で表示
|
| 78 |
-
|
| 79 |
-
save_name = file_name # 保存用のパワポのファイル名
|
| 80 |
-
prs = Presentation() # Presentationクラスをインスタンス化
|
| 81 |
-
|
| 82 |
-
# 1枚目
|
| 83 |
-
title_slide_layout = prs.slide_layouts[0]
|
| 84 |
-
slide = prs.slides.add_slide(title_slide_layout)
|
| 85 |
-
title = slide.shapes.title
|
| 86 |
-
subtitle = slide.placeholders[1]
|
| 87 |
-
title.text = meta["main_title"]
|
| 88 |
-
subtitle.text = today
|
| 89 |
-
|
| 90 |
-
# フォントサイズを変更
|
| 91 |
-
for paragraph in title.text_frame.paragraphs:
|
| 92 |
-
paragraph.font.size = Pt(24)
|
| 93 |
-
|
| 94 |
-
# フォントサイズを変更
|
| 95 |
-
for paragraph in subtitle.text_frame.paragraphs:
|
| 96 |
-
paragraph.font.size = Pt(10)
|
| 97 |
-
|
| 98 |
-
logo = meta["logo"]
|
| 99 |
-
|
| 100 |
-
print("logo:",logo)
|
| 101 |
-
# リクエストを送信して画像データを取得
|
| 102 |
-
logoresponse = requests.get(logo)
|
| 103 |
-
|
| 104 |
-
logoname = os.path.basename(logo)
|
| 105 |
-
|
| 106 |
-
# ステータスコードを確認
|
| 107 |
-
if logoresponse.status_code == 200:
|
| 108 |
-
|
| 109 |
-
# ローカルファイルに保存
|
| 110 |
-
with open(logoname, 'wb') as file:
|
| 111 |
-
file.write(logoresponse.content)
|
| 112 |
-
corplogoename = "./" + logoname
|
| 113 |
-
picture = slide.shapes.add_picture(corplogoename, Inches(0.2), Inches(0.2), width=Inches(0.5), height=Inches(0.5))
|
| 114 |
-
|
| 115 |
-
if os.path.exists(corplogoename):
|
| 116 |
-
os.remove(corplogoename)
|
| 117 |
-
else:
|
| 118 |
-
picture = slide.shapes.add_picture("/Users/richardhuh/Desktop/stock_research/ryhlogo.png", Inches(0.2), Inches(0.2), width=Inches(0.5), height=Inches(0.5))
|
| 119 |
-
|
| 120 |
-
# 2枚目
|
| 121 |
-
title_slide_layout = prs.slide_layouts[1]
|
| 122 |
-
slide = prs.slides.add_slide(title_slide_layout)
|
| 123 |
-
title = slide.shapes.title
|
| 124 |
-
subtitle = slide.placeholders[1]
|
| 125 |
-
title.text = "目次"
|
| 126 |
-
body_shape = slide.placeholders[1]
|
| 127 |
-
|
| 128 |
-
p = body_shape.text_frame.add_paragraph()
|
| 129 |
-
p.text = '1. '+meta["mokuji1"]
|
| 130 |
-
p.level = 1
|
| 131 |
-
p.font.size = Pt(12)
|
| 132 |
-
|
| 133 |
-
p = body_shape.text_frame.add_paragraph()
|
| 134 |
-
p.text = '2. '+meta["mokuji2"]
|
| 135 |
-
p.level = 1
|
| 136 |
-
p.font.size = Pt(12)
|
| 137 |
-
|
| 138 |
-
p = body_shape.text_frame.add_paragraph()
|
| 139 |
-
p.text = '3. '+meta["mokuji3"]
|
| 140 |
-
p.level = 1
|
| 141 |
-
p.font.size = Pt(12)
|
| 142 |
-
|
| 143 |
-
p = body_shape.text_frame.add_paragraph()
|
| 144 |
-
p.text = '4. '+meta["mokuji4"]
|
| 145 |
-
p.level = 1
|
| 146 |
-
p.font.size = Pt(12)
|
| 147 |
-
|
| 148 |
-
# 3枚目
|
| 149 |
-
title_slide_layout = prs.slide_layouts[1]
|
| 150 |
-
slide = prs.slides.add_slide(title_slide_layout)
|
| 151 |
-
title = slide.shapes.title
|
| 152 |
-
title.text = meta["p3_title"]
|
| 153 |
-
|
| 154 |
-
# フォントサ���ズを変更
|
| 155 |
-
for paragraph in title.text_frame.paragraphs:
|
| 156 |
-
paragraph.font.size = Pt(20)
|
| 157 |
-
|
| 158 |
-
body_shape = slide.placeholders[1]
|
| 159 |
-
p = body_shape.text_frame.add_paragraph()
|
| 160 |
-
p.text = meta["p3_body"]
|
| 161 |
-
p.level = 1
|
| 162 |
-
p.font.size = Pt(12)
|
| 163 |
-
|
| 164 |
-
#picture = slide.shapes.add_picture("https://www.ryhintl.com/images/ryhlogo/ryhlogo.png", Inches(1), Inches(4), width=Inches(3), height=Inches(2))
|
| 165 |
-
|
| 166 |
-
# 4枚目
|
| 167 |
-
title_slide_layout = prs.slide_layouts[1]
|
| 168 |
-
slide = prs.slides.add_slide(title_slide_layout)
|
| 169 |
-
title = slide.shapes.title
|
| 170 |
-
subtitle = slide.placeholders[1]
|
| 171 |
-
title.text = "2. "+meta["p4_title"]
|
| 172 |
-
# フォントサイズを変更
|
| 173 |
-
for paragraph in title.text_frame.paragraphs:
|
| 174 |
-
paragraph.font.size = Pt(20)
|
| 175 |
-
|
| 176 |
-
body_shape = slide.placeholders[1]
|
| 177 |
-
p = body_shape.text_frame.add_paragraph()
|
| 178 |
-
p.text = meta["p4_body1"]
|
| 179 |
-
p.level = 1
|
| 180 |
-
p.font.size = Pt(12)
|
| 181 |
-
|
| 182 |
-
p = body_shape.text_frame.add_paragraph()
|
| 183 |
-
p.text = meta["p4_body2"]
|
| 184 |
-
p.level = 1
|
| 185 |
-
p.font.size = Pt(12)
|
| 186 |
-
|
| 187 |
-
p = body_shape.text_frame.add_paragraph()
|
| 188 |
-
p.text = meta["p4_body3"]
|
| 189 |
-
p.level = 1
|
| 190 |
-
p.font.size = Pt(12)
|
| 191 |
-
|
| 192 |
-
# 5枚目
|
| 193 |
-
title_slide_layout = prs.slide_layouts[1]
|
| 194 |
-
slide = prs.slides.add_slide(title_slide_layout)
|
| 195 |
-
title = slide.shapes.title
|
| 196 |
-
title.text = "3. "+meta["p5_title"]
|
| 197 |
-
# フォントサイズを変更
|
| 198 |
-
for paragraph in title.text_frame.paragraphs:
|
| 199 |
-
paragraph.font.size = Pt(20)
|
| 200 |
-
|
| 201 |
-
body_shape = slide.placeholders[1]
|
| 202 |
-
|
| 203 |
-
p = body_shape.text_frame.add_paragraph()
|
| 204 |
-
p.text = meta["p5_body1"]
|
| 205 |
-
p.level = 1
|
| 206 |
-
p.font.bold = True
|
| 207 |
-
p.font.size = Pt(12)
|
| 208 |
-
|
| 209 |
-
p = body_shape.text_frame.add_paragraph()
|
| 210 |
-
p.text = meta["p5_body2"]
|
| 211 |
-
p.level = 1
|
| 212 |
-
p.font.bold = True
|
| 213 |
-
p.font.size = Pt(12)
|
| 214 |
-
|
| 215 |
-
p = body_shape.text_frame.add_paragraph()
|
| 216 |
-
p.text = meta["p5_body3"]
|
| 217 |
-
p.level = 1
|
| 218 |
-
p.font.bold = True
|
| 219 |
-
p.font.size = Pt(12)
|
| 220 |
-
|
| 221 |
-
# 6枚目
|
| 222 |
-
title_slide_layout = prs.slide_layouts[1]
|
| 223 |
-
slide = prs.slides.add_slide(title_slide_layout)
|
| 224 |
-
title = slide.shapes.title
|
| 225 |
-
subtitle = slide.placeholders[1]
|
| 226 |
-
|
| 227 |
-
title.text = "4."+meta["p6_title"]
|
| 228 |
-
body_shape = slide.placeholders[1]
|
| 229 |
-
subtitle.text = meta["p6_body"]
|
| 230 |
-
|
| 231 |
-
# フォントサイズを変更
|
| 232 |
-
for paragraph in title.text_frame.paragraphs:
|
| 233 |
-
paragraph.font.size = Pt(20)
|
| 234 |
-
|
| 235 |
-
# フォントサイズを変更
|
| 236 |
-
for paragraph in subtitle.text_frame.paragraphs:
|
| 237 |
-
paragraph.font.size = Pt(10)
|
| 238 |
-
|
| 239 |
-
p = body_shape.text_frame.add_paragraph()
|
| 240 |
-
p.text = meta["p6_para1"]
|
| 241 |
-
p.level = 1
|
| 242 |
-
p.font.bold = True
|
| 243 |
-
p.font.size = Pt(12)
|
| 244 |
-
|
| 245 |
-
p = body_shape.text_frame.add_paragraph()
|
| 246 |
-
p.text = meta["p6_para2"]
|
| 247 |
-
p.level = 1
|
| 248 |
-
p.font.bold = True
|
| 249 |
-
p.font.size = Pt(12)
|
| 250 |
-
|
| 251 |
-
# 7枚目
|
| 252 |
-
title_slide_layout = prs.slide_layouts[1]
|
| 253 |
-
slide = prs.slides.add_slide(title_slide_layout)
|
| 254 |
-
title = slide.shapes.title
|
| 255 |
-
title.text = meta["p7_title"]
|
| 256 |
-
|
| 257 |
-
# フォントサイズを変更
|
| 258 |
-
for paragraph in title.text_frame.paragraphs:
|
| 259 |
-
paragraph.font.size = Pt(20)
|
| 260 |
-
|
| 261 |
-
body_shape = slide.placeholders[1]
|
| 262 |
-
p = body_shape.text_frame.add_paragraph()
|
| 263 |
-
p.text = meta["p7_body"]
|
| 264 |
-
p.level = 1
|
| 265 |
-
p.font.size = Pt(12)
|
| 266 |
-
|
| 267 |
-
url = meta["p7_img"]
|
| 268 |
-
|
| 269 |
-
# 保存するファイル名
|
| 270 |
-
fname = os.path.basename(url)
|
| 271 |
-
|
| 272 |
-
filename = "./" + fname
|
| 273 |
-
|
| 274 |
-
# リクエストを送信して画像データを取得
|
| 275 |
-
response = requests.get(url)
|
| 276 |
-
|
| 277 |
-
# ステータスコードを確認
|
| 278 |
-
if response.status_code == 200:
|
| 279 |
-
|
| 280 |
-
# ローカルファイルに保存
|
| 281 |
-
with open(filename, 'wb') as file:
|
| 282 |
-
file.write(response.content)
|
| 283 |
-
picture = slide.shapes.add_picture(filename, Inches(1), Inches(4), width=Inches(3), height=Inches(2))
|
| 284 |
-
|
| 285 |
-
if os.path.exists(filename):
|
| 286 |
-
os.remove(filename)
|
| 287 |
-
else:
|
| 288 |
-
print(f"ダウンロードに失敗しました。ステータスコード: {response.status_code}")
|
| 289 |
-
|
| 290 |
-
prs.save(file_name)
|
| 291 |
-
return f"ファイル '{file_name}' が生成されました!"
|
| 292 |
-
|
| 293 |
|
| 294 |
def greeting(profile: gr.OAuthProfile | None) -> str:
|
| 295 |
if profile is None:
|
|
@@ -477,15 +222,6 @@ def search(state,query: str):
|
|
| 477 |
|
| 478 |
return final,state["score"]
|
| 479 |
|
| 480 |
-
dataid = requests.get("https://www.ryhintl.com/dbjson/getjson?sqlcmd=select main_title from ku_keyslides")
|
| 481 |
-
|
| 482 |
-
# Decode the JSON response
|
| 483 |
-
data_str = dataid.content.decode('utf-8')
|
| 484 |
-
data = eval(data_str)
|
| 485 |
-
|
| 486 |
-
# ラベルと値のペアに変換
|
| 487 |
-
choices = [item["main_title"] for item in data]
|
| 488 |
-
|
| 489 |
# Gradio Blocks Interface
|
| 490 |
with gr.Blocks(css="footer {visibility: hidden;} .custom-image {width: 64px; height: 64px;} .custom-btn {width: 150px; height: 30px; background-color: lightblue; border-radius: 10px; font-size: 12px; color: #3C82F6;} #header {display: flex; justify-content: space-between; align-items: center; font-size: 24px; font-weight: bold;} #logo {width: 50px; height: 50px;}",title="Knowledge Utility",theme=gr.themes.Glass()) as ku:
|
| 491 |
state = gr.State({
|
|
@@ -623,21 +359,6 @@ with gr.Blocks(css="footer {visibility: hidden;} .custom-image {width: 64px; hei
|
|
| 623 |
|
| 624 |
submit_button.click(process_invitees, inputs=[state,input_text], outputs=output_text)
|
| 625 |
|
| 626 |
-
with gr.Tab("スライド作成"):
|
| 627 |
-
with gr.Row():
|
| 628 |
-
gr.Markdown("📧 ベクターDBに保存されている知識ベースのインベントリを使用してスライドを作成します。")
|
| 629 |
-
|
| 630 |
-
with gr.Row():
|
| 631 |
-
file_name_input = gr.Textbox(label="ファイル名を入力してください", value="test.pptx")
|
| 632 |
-
find_key = gr.Dropdown(choices, label="キー・スライドを選択")
|
| 633 |
-
|
| 634 |
-
with gr.Row():
|
| 635 |
-
output = gr.Textbox(label="結果")
|
| 636 |
-
|
| 637 |
-
with gr.Row():
|
| 638 |
-
generate_button = gr.Button("生成")
|
| 639 |
-
generate_button.click(create_metapptx, inputs=[file_name_input,find_key], outputs=output)
|
| 640 |
-
|
| 641 |
# Launch the app
|
| 642 |
ku.load(list_private_models, inputs=None, outputs=[m2, tab_find, tab_reg])
|
| 643 |
ku.launch(favicon_path="favicon.ico",share=True)
|
|
|
|
| 12 |
import base64
|
| 13 |
import requests
|
| 14 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
load_dotenv(verbose=True)
|
| 16 |
|
| 17 |
# Initialize Qdrant and Cohere clients
|
|
|
|
| 35 |
picture=""
|
| 36 |
)'''
|
| 37 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 225 |
# Gradio Blocks Interface
|
| 226 |
with gr.Blocks(css="footer {visibility: hidden;} .custom-image {width: 64px; height: 64px;} .custom-btn {width: 150px; height: 30px; background-color: lightblue; border-radius: 10px; font-size: 12px; color: #3C82F6;} #header {display: flex; justify-content: space-between; align-items: center; font-size: 24px; font-weight: bold;} #logo {width: 50px; height: 50px;}",title="Knowledge Utility",theme=gr.themes.Glass()) as ku:
|
| 227 |
state = gr.State({
|
|
|
|
| 359 |
|
| 360 |
submit_button.click(process_invitees, inputs=[state,input_text], outputs=output_text)
|
| 361 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 362 |
# Launch the app
|
| 363 |
ku.load(list_private_models, inputs=None, outputs=[m2, tab_find, tab_reg])
|
| 364 |
ku.launch(favicon_path="favicon.ico",share=True)
|