Spaces:
Runtime error
Runtime error
edit app.py
Browse files- app.py +1 -1
- app_test.py +0 -95
- base.py +0 -19
app.py
CHANGED
@@ -34,7 +34,7 @@ def _execute_function(function_call, chat_messages, guess_result):
|
|
34 |
)
|
35 |
if function_call["name"] == "guess_word":
|
36 |
guess_result = function_response
|
37 |
-
print(function_response)
|
38 |
# Step 4: send the info on the function call and function response to GPT
|
39 |
chat_messages.append(
|
40 |
{"role": "function",
|
|
|
34 |
)
|
35 |
if function_call["name"] == "guess_word":
|
36 |
guess_result = function_response
|
37 |
+
print("response: ", function_response)
|
38 |
# Step 4: send the info on the function call and function response to GPT
|
39 |
chat_messages.append(
|
40 |
{"role": "function",
|
app_test.py
DELETED
@@ -1,95 +0,0 @@
|
|
1 |
-
import time
|
2 |
-
|
3 |
-
import pandas as pd
|
4 |
-
import gradio as gr
|
5 |
-
import openai
|
6 |
-
|
7 |
-
|
8 |
-
with gr.Blocks() as demo:
|
9 |
-
|
10 |
-
with gr.Row():
|
11 |
-
gr.Markdown(
|
12 |
-
"""
|
13 |
-
# やりとりSemantle
|
14 |
-
[semantle日本語版](https://semantoru.com/)をchatbotと楽しめるためのspaceです。
|
15 |
-
## ゲームのやり方
|
16 |
-
- 正解は一つの単語で、これを答えるとゲームの勝利になります。
|
17 |
-
- 推測した単語が正解じゃない場合、類似度スコアと順位が表示されます。それは正解を推測する大事なヒントになります。
|
18 |
-
## chatbotの仕事
|
19 |
-
- 単語のスコアとランク以外に他のヒントがもらえます。
|
20 |
-
- ゲームに関して困っている時、何か質問してみてください。
|
21 |
-
"""
|
22 |
-
)
|
23 |
-
|
24 |
-
with gr.Row():
|
25 |
-
with gr.Column():
|
26 |
-
api_key = gr.Textbox(placeholder="sk-...", label="OPENAI_API_KEY", value=None, type="password")
|
27 |
-
idx = gr.State(value=0)
|
28 |
-
guessed = gr.State(value=set())
|
29 |
-
guesses = gr.State(value=list())
|
30 |
-
cur_guess = gr.State()
|
31 |
-
cur_guess_view = gr.Textbox(
|
32 |
-
interactive=False,
|
33 |
-
elem_id="cur-guess-view",
|
34 |
-
show_label=False,
|
35 |
-
)
|
36 |
-
guesses_table = gr.DataFrame(
|
37 |
-
value=pd.DataFrame(columns=["#", "答え", "スコア", "ランク"]),
|
38 |
-
headers=["#", "答え", "スコア", "ランク"],
|
39 |
-
datatype=["number", "str", "number", "str"],
|
40 |
-
elem_id="guesses-table",
|
41 |
-
interactive=False
|
42 |
-
)
|
43 |
-
with gr.Column(elem_id="chat_container"):
|
44 |
-
msg = gr.Textbox(
|
45 |
-
placeholder="ゲームをするため、まずはAPI KEYを入れてください。",
|
46 |
-
label="答え",
|
47 |
-
interactive=False,
|
48 |
-
max_lines=1
|
49 |
-
)
|
50 |
-
chatbot = gr.Chatbot(elem_id="chatbot")
|
51 |
-
|
52 |
-
def unfreeze():
|
53 |
-
return msg.update(interactive=True, placeholder="正解と思う言葉を答えてください。")
|
54 |
-
def greet():
|
55 |
-
return "", [("[START]", "ゲームを始まります!好きな言葉をひとつだけいってみてください。")]
|
56 |
-
|
57 |
-
def respond(key, user_input, chat_history, cur):
|
58 |
-
reply = {"content": ["tesT", 0.9, 1]}
|
59 |
-
# reply = {"content": "hint"}
|
60 |
-
if isinstance(reply["content"], list):
|
61 |
-
cur = reply["content"]
|
62 |
-
cur_view = " | ".join([str(_) for _ in cur])
|
63 |
-
reply = {"content": "updated"}
|
64 |
-
chat_history.append((user_input, reply["content"]))
|
65 |
-
time.sleep(2)
|
66 |
-
return "", chat_history, cur, cur_view
|
67 |
-
|
68 |
-
def update_guesses(cur, i, guessed_words, guesses_df):
|
69 |
-
print(cur)
|
70 |
-
if cur[2] not in guessed_words:
|
71 |
-
guessed_words.add(cur[0])
|
72 |
-
guesses_df.loc[i] = [i] + cur
|
73 |
-
i += 1
|
74 |
-
print(guesses_df)
|
75 |
-
guesses_df = guesses_df.sort_values(by=["スコア"], ascending=False)
|
76 |
-
return i, guessed_words, guesses_df
|
77 |
-
|
78 |
-
api_key.change(unfreeze, [], [msg]).then(greet, [], [msg, chatbot])
|
79 |
-
msg.submit(respond, [api_key, msg, chatbot, cur_guess], [msg, chatbot, cur_guess, cur_guess_view])
|
80 |
-
cur_guess_view.change(update_guesses, [cur_guess, idx, guessed, guesses_table], [idx, guessed, guesses_table])
|
81 |
-
|
82 |
-
gr.Examples(
|
83 |
-
[
|
84 |
-
["猫"],
|
85 |
-
["どんなヒントが貰える?"],
|
86 |
-
["正解と「近い」とはどういう意味?"],
|
87 |
-
["何から始めたらいい?"],
|
88 |
-
["今日の正解は何?"],
|
89 |
-
],
|
90 |
-
inputs=msg,
|
91 |
-
label="こちらから選んで話すこともできます."
|
92 |
-
)
|
93 |
-
|
94 |
-
if __name__ == "__main__":
|
95 |
-
demo.queue(concurrency_count=20).launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
base.py
DELETED
@@ -1,19 +0,0 @@
|
|
1 |
-
# from typing import List
|
2 |
-
|
3 |
-
# class Tool:
|
4 |
-
# description: str = "Calculate a score and a rank of the guess word, which indicate a distance from the secret word."
|
5 |
-
# name: str = "evaluate_score"
|
6 |
-
|
7 |
-
# inputs: List[str] = ["word", "puzzle_num"]
|
8 |
-
# required: List[str] = ["word", "puzzle_num"]
|
9 |
-
|
10 |
-
# def __init__(self, *args, **kwargs):
|
11 |
-
# pass
|
12 |
-
|
13 |
-
# def setup(self):
|
14 |
-
|
15 |
-
# def __call__(self, *args, **kwargs):
|
16 |
-
# args = [arg for arg in args]
|
17 |
-
# kwargs = {k: v for k, v in kwargs.items()}
|
18 |
-
|
19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|