Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -19,21 +19,9 @@ print (loaded_model)
|
|
19 |
now = datetime.now()
|
20 |
date_time_str = now.strftime("%Y-%m-%d %H:%M:%S")
|
21 |
|
22 |
-
client = InferenceClient(
|
23 |
-
"mistralai/Mixtral-8x7B-Instruct-v0.1"
|
24 |
-
)
|
25 |
-
|
26 |
-
############################################
|
27 |
-
model = gr.load("models/stabilityai/sdxl-turbo")
|
28 |
-
|
29 |
-
VERBOSE = True
|
30 |
-
MAX_HISTORY = 10000
|
31 |
-
#MODEL = "gpt-3.5-turbo" # "gpt-4"
|
32 |
history = []
|
33 |
|
34 |
-
def infer(txt):
|
35 |
-
return (model(txt))
|
36 |
-
|
37 |
def format_prompt(message, history):
|
38 |
prompt = "<s>"
|
39 |
for user_prompt, bot_response in history:
|
@@ -42,12 +30,7 @@ def format_prompt(message, history):
|
|
42 |
prompt += f"[INST] {message} [/INST]"
|
43 |
return prompt
|
44 |
|
45 |
-
|
46 |
-
|
47 |
-
def run_gpt(
|
48 |
-
in_prompt,
|
49 |
-
history,
|
50 |
-
):
|
51 |
print(f'history :: {history}')
|
52 |
prompt=format_prompt(in_prompt,history)
|
53 |
seed = random.randint(1,1111111111111111)
|
@@ -60,21 +43,12 @@ def run_gpt(
|
|
60 |
do_sample=True,
|
61 |
seed=seed,
|
62 |
)
|
63 |
-
|
64 |
-
|
65 |
content = agent.GENERATE_PROMPT + prompt
|
66 |
-
|
67 |
print(content)
|
68 |
-
|
69 |
-
#formatted_prompt = format_prompt(f"{system_prompt}, {prompt}", history)
|
70 |
-
#formatted_prompt = format_prompt(f'{content}', history)
|
71 |
-
|
72 |
stream = client.text_generation(content, **generate_kwargs, stream=True, details=True, return_full_text=False)
|
73 |
resp = ""
|
74 |
for response in stream:
|
75 |
resp += response.token.text
|
76 |
-
|
77 |
-
#history.append((in_prompt,resp))
|
78 |
return resp
|
79 |
|
80 |
|
@@ -108,8 +82,6 @@ def run(purpose,history,model_drop):
|
|
108 |
else:
|
109 |
yield ([(purpose,"an Error occured")],None)
|
110 |
|
111 |
-
|
112 |
-
|
113 |
################################################
|
114 |
|
115 |
with gr.Blocks() as iface:
|
@@ -117,27 +89,15 @@ with gr.Blocks() as iface:
|
|
117 |
#chatbot=gr.Chatbot(show_label=False, show_share_button=False, show_copy_button=True, likeable=True, layout="panel"),
|
118 |
with gr.Row():
|
119 |
with gr.Column():
|
120 |
-
chatbot=gr.Chatbot()
|
121 |
msg = gr.Textbox()
|
122 |
model_drop=gr.Dropdown(label="Diffusion Models", type="index", choices=[m for m in models], value=models[0])
|
123 |
with gr.Row():
|
124 |
submit_b = gr.Button()
|
125 |
stop_b = gr.Button("Stop")
|
126 |
clear = gr.ClearButton([msg, chatbot])
|
127 |
-
|
128 |
sumbox=gr.Image(label="Image")
|
129 |
-
|
130 |
-
|
131 |
sub_b = submit_b.click(run, [msg,chatbot,model_drop],[chatbot,sumbox])
|
132 |
sub_e = msg.submit(run, [msg, chatbot,model_drop], [chatbot,sumbox])
|
133 |
stop_b.click(None,None,None, cancels=[sub_b,sub_e])
|
134 |
iface.launch()
|
135 |
-
'''
|
136 |
-
gr.ChatInterface(
|
137 |
-
fn=run,
|
138 |
-
chatbot=gr.Chatbot(show_label=False, show_share_button=False, show_copy_button=True, likeable=True, layout="panel"),
|
139 |
-
title="Mixtral 46.7B\nMicro-Agent\nInternet Search <br> development test",
|
140 |
-
examples=examples,
|
141 |
-
concurrency_limit=20,
|
142 |
-
).launch(show_api=False)
|
143 |
-
'''
|
|
|
19 |
now = datetime.now()
|
20 |
date_time_str = now.strftime("%Y-%m-%d %H:%M:%S")
|
21 |
|
22 |
+
client = InferenceClient("mistralai/Mixtral-8x7B-Instruct-v0.1")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
history = []
|
24 |
|
|
|
|
|
|
|
25 |
def format_prompt(message, history):
|
26 |
prompt = "<s>"
|
27 |
for user_prompt, bot_response in history:
|
|
|
30 |
prompt += f"[INST] {message} [/INST]"
|
31 |
return prompt
|
32 |
|
33 |
+
def run_gpt(in_prompt,history):
|
|
|
|
|
|
|
|
|
|
|
34 |
print(f'history :: {history}')
|
35 |
prompt=format_prompt(in_prompt,history)
|
36 |
seed = random.randint(1,1111111111111111)
|
|
|
43 |
do_sample=True,
|
44 |
seed=seed,
|
45 |
)
|
|
|
|
|
46 |
content = agent.GENERATE_PROMPT + prompt
|
|
|
47 |
print(content)
|
|
|
|
|
|
|
|
|
48 |
stream = client.text_generation(content, **generate_kwargs, stream=True, details=True, return_full_text=False)
|
49 |
resp = ""
|
50 |
for response in stream:
|
51 |
resp += response.token.text
|
|
|
|
|
52 |
return resp
|
53 |
|
54 |
|
|
|
82 |
else:
|
83 |
yield ([(purpose,"an Error occured")],None)
|
84 |
|
|
|
|
|
85 |
################################################
|
86 |
|
87 |
with gr.Blocks() as iface:
|
|
|
89 |
#chatbot=gr.Chatbot(show_label=False, show_share_button=False, show_copy_button=True, likeable=True, layout="panel"),
|
90 |
with gr.Row():
|
91 |
with gr.Column():
|
92 |
+
chatbot=gr.Chatbot(show_copy_button=True, layout='panel')
|
93 |
msg = gr.Textbox()
|
94 |
model_drop=gr.Dropdown(label="Diffusion Models", type="index", choices=[m for m in models], value=models[0])
|
95 |
with gr.Row():
|
96 |
submit_b = gr.Button()
|
97 |
stop_b = gr.Button("Stop")
|
98 |
clear = gr.ClearButton([msg, chatbot])
|
|
|
99 |
sumbox=gr.Image(label="Image")
|
|
|
|
|
100 |
sub_b = submit_b.click(run, [msg,chatbot,model_drop],[chatbot,sumbox])
|
101 |
sub_e = msg.submit(run, [msg, chatbot,model_drop], [chatbot,sumbox])
|
102 |
stop_b.click(None,None,None, cancels=[sub_b,sub_e])
|
103 |
iface.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|