malvika2003 commited on
Commit
9888b7c
1 Parent(s): a7b522a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +95 -95
app.py CHANGED
@@ -1,95 +1,95 @@
1
- import gradio as gr
2
-
3
- examples = [
4
- "Give me a recipe for pizza with pineapple",
5
- "Write me a tweet about the new OpenVINO release",
6
- "Explain the difference between CPU and GPU",
7
- "Give five ideas for a great weekend with family",
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
- def run_generation(user_text, top_p, temperature, top_k, max_new_tokens, performance):
17
- # Example response, replace with actual model call
18
- response = f"Generated text for: {user_text}"
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(
34
- placeholder="Write an email about an alpaca that likes flan",
35
- label="User instruction",
36
- )
37
- model_output = gr.Textbox(label="Model response", interactive=False)
38
- performance = gr.Textbox(label="Performance", lines=1, interactive=False)
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
- if __name__ == "__main__":
94
- demo.queue()
95
- demo.launch()
 
1
+ import gradio as gr
2
+
3
+ examples = [
4
+ "Give me a recipe for pizza with pineapple",
5
+ "Write me a tweet about the new OpenVINO release",
6
+ "Explain the difference between CPU and GPU",
7
+ "Give five ideas for a great weekend with family",
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
+ def run_generation(user_text, top_p, temperature, top_k, max_new_tokens, performance):
17
+ # Example response, replace with actual model call
18
+ response = f"Generated text for: {user_text}"
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(
34
+ placeholder="Write an email about an alpaca that likes flan",
35
+ label="User instruction",
36
+ )
37
+ model_output = gr.Textbox(label="Model response", interactive=False)
38
+ performance = gr.Textbox(label="Performance", lines=1, interactive=False)
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
+ if __name__ == "__main__":
94
+ demo.queue()
95
+ demo.launch(share=True)