Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,33 +1,18 @@
|
|
1 |
import gradio as gr
|
|
|
2 |
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
"
|
7 |
-
|
8 |
-
"Do Androids dream of Electric sheep?",
|
9 |
-
"Who is Dolly?",
|
10 |
-
"Please give me advice on how to write resume?",
|
11 |
-
"Name 3 advantages to being a cat",
|
12 |
-
"Write instructions on how to become a good AI engineer",
|
13 |
-
"Write a love letter to my best friend",
|
14 |
-
]
|
15 |
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
performance = "N/A" # Replace with actual performance metrics if available
|
20 |
-
return response, performance
|
21 |
-
|
22 |
-
def reset_textbox(*args):
|
23 |
-
return "", "", ""
|
24 |
-
|
25 |
-
with gr.Blocks() as demo:
|
26 |
-
gr.Markdown(
|
27 |
-
"# Question Answering with OpenVINO\n"
|
28 |
-
"Provide instruction which describes a task below or select among predefined examples and model writes response that performs requested task."
|
29 |
-
)
|
30 |
|
|
|
|
|
31 |
with gr.Row():
|
32 |
with gr.Column(scale=4):
|
33 |
user_text = gr.Textbox(
|
@@ -39,57 +24,7 @@ with gr.Blocks() as demo:
|
|
39 |
with gr.Column(scale=1):
|
40 |
button_clear = gr.Button(value="Clear")
|
41 |
button_submit = gr.Button(value="Submit")
|
42 |
-
gr.Examples(examples, user_text)
|
43 |
-
with gr.Column(scale=1):
|
44 |
-
max_new_tokens = gr.Slider(
|
45 |
-
minimum=1,
|
46 |
-
maximum=1000,
|
47 |
-
value=256,
|
48 |
-
step=1,
|
49 |
-
interactive=True,
|
50 |
-
label="Max New Tokens",
|
51 |
-
)
|
52 |
-
top_p = gr.Slider(
|
53 |
-
minimum=0.05,
|
54 |
-
maximum=1.0,
|
55 |
-
value=0.92,
|
56 |
-
step=0.05,
|
57 |
-
interactive=True,
|
58 |
-
label="Top-p (nucleus sampling)",
|
59 |
-
)
|
60 |
-
top_k = gr.Slider(
|
61 |
-
minimum=0,
|
62 |
-
maximum=50,
|
63 |
-
value=0,
|
64 |
-
step=1,
|
65 |
-
interactive=True,
|
66 |
-
label="Top-k",
|
67 |
-
)
|
68 |
-
temperature = gr.Slider(
|
69 |
-
minimum=0.1,
|
70 |
-
maximum=5.0,
|
71 |
-
value=0.8,
|
72 |
-
step=0.1,
|
73 |
-
interactive=True,
|
74 |
-
label="Temperature",
|
75 |
-
)
|
76 |
-
|
77 |
-
user_text.submit(
|
78 |
-
run_generation,
|
79 |
-
[user_text, top_p, temperature, top_k, max_new_tokens, performance],
|
80 |
-
[model_output, performance],
|
81 |
-
)
|
82 |
-
button_submit.click(
|
83 |
-
run_generation,
|
84 |
-
[user_text, top_p, temperature, top_k, max_new_tokens, performance],
|
85 |
-
[model_output, performance],
|
86 |
-
)
|
87 |
-
button_clear.click(
|
88 |
-
reset_textbox,
|
89 |
-
[user_text, model_output, performance],
|
90 |
-
[user_text, model_output, performance],
|
91 |
-
)
|
92 |
|
93 |
-
|
94 |
-
|
95 |
-
|
|
|
1 |
import gradio as gr
|
2 |
+
from transformers import AutoTokenizer, TextIteratorStreamer
|
3 |
|
4 |
+
# Define the models and their configurations
|
5 |
+
model_name = "phi-2"
|
6 |
+
model_configuration = {
|
7 |
+
"toeknizer_kwargs": {'model_id': 'susnato/phi-2', 'prompt_template': 'Instruct:{instruction}\nOutput:'}
|
8 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
|
10 |
+
# Load the tokenizer
|
11 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
12 |
+
tokenizer_kwargs = model_configuration.get("toeknizer_kwargs", {})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
|
14 |
+
# Define the Gradio interface
|
15 |
+
def main():
|
16 |
with gr.Row():
|
17 |
with gr.Column(scale=4):
|
18 |
user_text = gr.Textbox(
|
|
|
24 |
with gr.Column(scale=1):
|
25 |
button_clear = gr.Button(value="Clear")
|
26 |
button_submit = gr.Button(value="Submit")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
|
28 |
+
# Run the Gradio interface
|
29 |
+
iface = gr.Interface(fn=main, inputs=user_text, outputs=model_output, performance=performance, live=True)
|
30 |
+
iface.launch()
|