Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -14,14 +14,16 @@ import io
|
|
| 14 |
import chat_models
|
| 15 |
|
| 16 |
loaded_model=[]
|
|
|
|
| 17 |
for i,model in enumerate(models):
|
| 18 |
loaded_model.append(gr.load(f'models/{model}'))
|
| 19 |
print (loaded_model)
|
| 20 |
-
|
|
|
|
|
|
|
| 21 |
now = datetime.now()
|
| 22 |
date_time_str = now.strftime("%Y-%m-%d %H:%M:%S")
|
| 23 |
|
| 24 |
-
client = InferenceClient(chat_models.models[0])
|
| 25 |
#client = InferenceClient("mistralai/Mixtral-8x7B-Instruct-v0.1")
|
| 26 |
history = []
|
| 27 |
|
|
@@ -33,7 +35,8 @@ def format_prompt(message, history):
|
|
| 33 |
prompt += f"[INST] {message} [/INST]"
|
| 34 |
return prompt
|
| 35 |
|
| 36 |
-
def run_gpt(in_prompt,history):
|
|
|
|
| 37 |
print(f'history :: {history}')
|
| 38 |
prompt=format_prompt(in_prompt,history)
|
| 39 |
seed = random.randint(1,1111111111111111)
|
|
@@ -55,7 +58,7 @@ def run_gpt(in_prompt,history):
|
|
| 55 |
return resp
|
| 56 |
|
| 57 |
|
| 58 |
-
def run(purpose,history,model_drop):
|
| 59 |
print (history)
|
| 60 |
task=None
|
| 61 |
#if history:
|
|
@@ -64,7 +67,7 @@ def run(purpose,history,model_drop):
|
|
| 64 |
# history = ""
|
| 65 |
|
| 66 |
#action_name, action_input = parse_action(line)
|
| 67 |
-
out_prompt = run_gpt(purpose,history)
|
| 68 |
#yield ([(purpose,out_prompt)],None)
|
| 69 |
history.append((purpose,out_prompt))
|
| 70 |
yield (history,None)
|
|
@@ -105,16 +108,19 @@ with gr.Blocks(css=style) as iface:
|
|
| 105 |
gr.HTML("""<div class="top_head"><center><br><h1 class="top_h1">Mixtral Chat Diffusion</h1><br><h3 class="top_h1">This chatbot will generate images</h3></center></div?""")
|
| 106 |
#chatbot=gr.Chatbot(show_label=False, show_share_button=False, show_copy_button=True, likeable=True, layout="panel"),
|
| 107 |
with gr.Row():
|
| 108 |
-
with gr.Column():
|
| 109 |
chatbot=gr.Chatbot(show_copy_button=True, layout='panel')
|
| 110 |
msg = gr.Textbox()
|
| 111 |
model_drop=gr.Dropdown(label="Diffusion Models", type="index", choices=[m for m in models], value=models[0])
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
|
|
|
|
|
|
|
|
|
| 119 |
stop_b.click(None,None,None, cancels=[sub_b,sub_e])
|
| 120 |
iface.launch()
|
|
|
|
| 14 |
import chat_models
|
| 15 |
|
| 16 |
loaded_model=[]
|
| 17 |
+
chat_model=[]
|
| 18 |
for i,model in enumerate(models):
|
| 19 |
loaded_model.append(gr.load(f'models/{model}'))
|
| 20 |
print (loaded_model)
|
| 21 |
+
for i,model_c in enumerate(chat_models.models):
|
| 22 |
+
chat_model.append(model_c)
|
| 23 |
+
print (chat_model)
|
| 24 |
now = datetime.now()
|
| 25 |
date_time_str = now.strftime("%Y-%m-%d %H:%M:%S")
|
| 26 |
|
|
|
|
| 27 |
#client = InferenceClient("mistralai/Mixtral-8x7B-Instruct-v0.1")
|
| 28 |
history = []
|
| 29 |
|
|
|
|
| 35 |
prompt += f"[INST] {message} [/INST]"
|
| 36 |
return prompt
|
| 37 |
|
| 38 |
+
def run_gpt(in_prompt,history,model_drop):
|
| 39 |
+
client = InferenceClient(chat_models.models[int(model_drop)])
|
| 40 |
print(f'history :: {history}')
|
| 41 |
prompt=format_prompt(in_prompt,history)
|
| 42 |
seed = random.randint(1,1111111111111111)
|
|
|
|
| 58 |
return resp
|
| 59 |
|
| 60 |
|
| 61 |
+
def run(purpose,history,model_drop,chat_drop):
|
| 62 |
print (history)
|
| 63 |
task=None
|
| 64 |
#if history:
|
|
|
|
| 67 |
# history = ""
|
| 68 |
|
| 69 |
#action_name, action_input = parse_action(line)
|
| 70 |
+
out_prompt = run_gpt(purpose,history,model_drop)
|
| 71 |
#yield ([(purpose,out_prompt)],None)
|
| 72 |
history.append((purpose,out_prompt))
|
| 73 |
yield (history,None)
|
|
|
|
| 108 |
gr.HTML("""<div class="top_head"><center><br><h1 class="top_h1">Mixtral Chat Diffusion</h1><br><h3 class="top_h1">This chatbot will generate images</h3></center></div?""")
|
| 109 |
#chatbot=gr.Chatbot(show_label=False, show_share_button=False, show_copy_button=True, likeable=True, layout="panel"),
|
| 110 |
with gr.Row():
|
| 111 |
+
with gr.Column(scale=1):
|
| 112 |
chatbot=gr.Chatbot(show_copy_button=True, layout='panel')
|
| 113 |
msg = gr.Textbox()
|
| 114 |
model_drop=gr.Dropdown(label="Diffusion Models", type="index", choices=[m for m in models], value=models[0])
|
| 115 |
+
chat_model_drop=gr.Dropdown(label="Chatbot Models", type="index", choices=[m for m in chat_models.models], value=chat_models.models[0])
|
| 116 |
+
with gr.Group():
|
| 117 |
+
with gr.Row():
|
| 118 |
+
submit_b = gr.Button()
|
| 119 |
+
stop_b = gr.Button("Stop")
|
| 120 |
+
clear = gr.ClearButton([msg, chatbot])
|
| 121 |
+
with gr.Column(scale=2):
|
| 122 |
+
sumbox=gr.Image(label="Image")
|
| 123 |
+
sub_b = submit_b.click(run, [msg,chatbot,model_drop,chat_model_drop],[chatbot,sumbox])
|
| 124 |
+
sub_e = msg.submit(run, [msg, chatbot,model_drop,chat_model_drop], [chatbot,sumbox])
|
| 125 |
stop_b.click(None,None,None, cancels=[sub_b,sub_e])
|
| 126 |
iface.launch()
|