Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,50 +1,33 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from huggingface_hub import InferenceClient
|
| 3 |
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
|
|
|
|
|
|
|
|
|
| 8 |
|
|
|
|
| 9 |
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
system_message,
|
| 14 |
-
max_tokens,
|
| 15 |
-
temperature,
|
| 16 |
-
top_p,
|
| 17 |
-
):
|
| 18 |
-
messages = [{"role": "system", "content": system_message}]
|
| 19 |
-
|
| 20 |
-
for val in history:
|
| 21 |
-
if val[0]:
|
| 22 |
-
messages.append({"role": "user", "content": val[0]})
|
| 23 |
-
if val[1]:
|
| 24 |
-
messages.append({"role": "assistant", "content": val[1]})
|
| 25 |
-
|
| 26 |
-
messages.append({"role": "user", "content": message})
|
| 27 |
-
|
| 28 |
response = ""
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
)
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
"""
|
| 44 |
-
For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
|
| 45 |
-
"""
|
| 46 |
demo = gr.ChatInterface(
|
| 47 |
-
|
| 48 |
additional_inputs=[
|
| 49 |
gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
|
| 50 |
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
|
|
@@ -59,6 +42,5 @@ demo = gr.ChatInterface(
|
|
| 59 |
],
|
| 60 |
)
|
| 61 |
|
| 62 |
-
|
| 63 |
if __name__ == "__main__":
|
| 64 |
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
|
|
|
| 2 |
|
| 3 |
+
# Загрузка текстов из файлов лора
|
| 4 |
+
def load_lore_files():
|
| 5 |
+
lore_data = {}
|
| 6 |
+
for filename in ["vampires.txt", "kings.txt", "castles.txt"]:
|
| 7 |
+
with open(filename, "r", encoding="utf-8") as file:
|
| 8 |
+
lore_data[filename] = file.read()
|
| 9 |
+
return lore_data
|
| 10 |
|
| 11 |
+
lore_data = load_lore_files()
|
| 12 |
|
| 13 |
+
# Функция, которая ищет упоминания в лоре
|
| 14 |
+
def chatbot(message, history, system_message, max_tokens, temperature, top_p):
|
| 15 |
+
# Простой поиск по всем файлам лора
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
response = ""
|
| 17 |
+
for filename, text in lore_data.items():
|
| 18 |
+
if message.lower() in text.lower():
|
| 19 |
+
response += f"В файле {filename} есть что-то похожее на ваш запрос!\n"
|
| 20 |
+
if response == "":
|
| 21 |
+
return "Извините, ничего не нашёл по вашему запросу."
|
| 22 |
+
|
| 23 |
+
# Если есть ответ, добавляем его в историю
|
| 24 |
+
history.append((message, response))
|
| 25 |
+
return response, history
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
# Интерфейс чата с Gradio
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
demo = gr.ChatInterface(
|
| 30 |
+
chatbot,
|
| 31 |
additional_inputs=[
|
| 32 |
gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
|
| 33 |
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
|
|
|
|
| 42 |
],
|
| 43 |
)
|
| 44 |
|
|
|
|
| 45 |
if __name__ == "__main__":
|
| 46 |
demo.launch()
|