Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -2,6 +2,7 @@ import os
|
|
2 |
import torch
|
3 |
import gradio as gr
|
4 |
|
|
|
5 |
from gen import get_pretrained_models, get_output, setup_model_parallel
|
6 |
|
7 |
os.environ["RANK"] = "0"
|
@@ -12,16 +13,30 @@ os.environ["MASTER_PORT"] = "50505"
|
|
12 |
local_rank, world_size = setup_model_parallel()
|
13 |
generator = get_pretrained_models("7B", "tokenizer", local_rank, world_size)
|
14 |
|
|
|
|
|
15 |
def chat(user_input):
|
16 |
bot_response = get_output(generator, user_input)[0]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
response = ""
|
18 |
for word in bot_response.split(" "):
|
19 |
response += word + " "
|
20 |
yield [(user_input, response)]
|
21 |
|
22 |
with gr.Blocks() as demo:
|
|
|
|
|
23 |
chatbot = gr.Chatbot()
|
24 |
-
textbox = gr.Textbox("
|
25 |
|
26 |
textbox.submit(chat, textbox, chatbot)
|
27 |
|
|
|
2 |
import torch
|
3 |
import gradio as gr
|
4 |
|
5 |
+
from strings import TITLE, ABSTRACT
|
6 |
from gen import get_pretrained_models, get_output, setup_model_parallel
|
7 |
|
8 |
os.environ["RANK"] = "0"
|
|
|
13 |
local_rank, world_size = setup_model_parallel()
|
14 |
generator = get_pretrained_models("7B", "tokenizer", local_rank, world_size)
|
15 |
|
16 |
+
history = []
|
17 |
+
|
18 |
def chat(user_input):
|
19 |
bot_response = get_output(generator, user_input)[0]
|
20 |
+
|
21 |
+
history.append({
|
22 |
+
"role": "user",
|
23 |
+
"content": user_input
|
24 |
+
})
|
25 |
+
history.append({
|
26 |
+
"role": "system",
|
27 |
+
"content": bot_response
|
28 |
+
})
|
29 |
+
|
30 |
response = ""
|
31 |
for word in bot_response.split(" "):
|
32 |
response += word + " "
|
33 |
yield [(user_input, response)]
|
34 |
|
35 |
with gr.Blocks() as demo:
|
36 |
+
gr.Markdown(f"## {TITLE}\n\n\n\n{ABSTRACT}")
|
37 |
+
|
38 |
chatbot = gr.Chatbot()
|
39 |
+
textbox = gr.Textbox(placeholder="Enter a prompt")
|
40 |
|
41 |
textbox.submit(chat, textbox, chatbot)
|
42 |
|