Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,5 +1,16 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import numpy as np
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
|
| 4 |
setsumei = '''
|
| 5 |
<!DOCTYPE html>
|
|
@@ -146,6 +157,26 @@ function createGradioAnimation() {
|
|
| 146 |
"""
|
| 147 |
|
| 148 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 149 |
def dyn_chart():
|
| 150 |
# 需要曲線と供給曲線のパラメータ
|
| 151 |
a = 100 # 需要曲線の切片
|
|
@@ -390,6 +421,28 @@ with gr.Blocks(css=load_css(),js=js) as llm:
|
|
| 390 |
</div>
|
| 391 |
""")
|
| 392 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 393 |
with gr.Tab("解説"):
|
| 394 |
gr.Markdown("# 📄 解説")
|
| 395 |
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import numpy as np
|
| 3 |
+
import requests
|
| 4 |
+
import cohere
|
| 5 |
+
from dotenv import load_dotenv
|
| 6 |
+
import os
|
| 7 |
+
|
| 8 |
+
load_dotenv(verbose=True)
|
| 9 |
+
coherekey = os.environ.get("COHERE_API_KEY")
|
| 10 |
+
co = cohere.ClientV2(api_key=coherekey)
|
| 11 |
+
|
| 12 |
+
cresponse = requests.get("https://www.ryhintl.com/chatgpt/dynamic.php")
|
| 13 |
+
cohere_doc = cresponse.json()
|
| 14 |
|
| 15 |
setsumei = '''
|
| 16 |
<!DOCTYPE html>
|
|
|
|
| 157 |
"""
|
| 158 |
|
| 159 |
|
| 160 |
+
def process_cohere(prompt):
|
| 161 |
+
|
| 162 |
+
if prompt == "":
|
| 163 |
+
return "プロンプトを入力してください。", "プロンプトは必須です。"
|
| 164 |
+
else:
|
| 165 |
+
system_message = """## あなたは、LLMのスペシャリストです。"""
|
| 166 |
+
messages = [
|
| 167 |
+
{"role": "system", "content": system_message},
|
| 168 |
+
{"role": "user", "content": prompt},
|
| 169 |
+
]
|
| 170 |
+
|
| 171 |
+
# Step 2: Tool planning and calling
|
| 172 |
+
response = co.chat(
|
| 173 |
+
model="command-r-plus-08-2024",
|
| 174 |
+
messages=messages,
|
| 175 |
+
documents=cohere_doc
|
| 176 |
+
)
|
| 177 |
+
return response.message.content[0].text
|
| 178 |
+
|
| 179 |
+
|
| 180 |
def dyn_chart():
|
| 181 |
# 需要曲線と供給曲線のパラメータ
|
| 182 |
a = 100 # 需要曲線の切片
|
|
|
|
| 421 |
</div>
|
| 422 |
""")
|
| 423 |
|
| 424 |
+
with gr.Tab("RAG"):
|
| 425 |
+
gr.Markdown("# 🗞️ RAG")
|
| 426 |
+
with gr.Row():
|
| 427 |
+
rag_input = gr.Textbox(label="プロンプト",value="最適価格導出のアプローチについて詳しく教えてください。")
|
| 428 |
+
|
| 429 |
+
with gr.Row():
|
| 430 |
+
rag_output = gr.Textbox(label="AIアシスタントの応答")
|
| 431 |
+
|
| 432 |
+
submit_button = gr.Button("RAGプロセス", variant="primary")
|
| 433 |
+
submit_button.click(
|
| 434 |
+
process_cohere,
|
| 435 |
+
inputs=[rag_input],
|
| 436 |
+
outputs=[rag_output]
|
| 437 |
+
)
|
| 438 |
+
|
| 439 |
+
# Add the Groq badge
|
| 440 |
+
gr.HTML("""
|
| 441 |
+
<div id="groq-badge">
|
| 442 |
+
<div style="color: #f55036; font-weight: bold;">POWERED BY EPRAG</div>
|
| 443 |
+
</div>
|
| 444 |
+
""")
|
| 445 |
+
|
| 446 |
with gr.Tab("解説"):
|
| 447 |
gr.Markdown("# 📄 解説")
|
| 448 |
|