Dinethnethsara2010 commited on
Commit
56d6d11
1 Parent(s): 3286a2f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -87
app.py CHANGED
@@ -38,92 +38,36 @@ def generate(
38
  yield output
39
  return output
40
 
41
- def style():
42
- return """
43
- <style>
44
- .title {
45
- font-size: 24px;
46
- font-weight: bold;
47
- color: #333;
48
- margin-bottom: 10px;
49
- }
50
- .container {
51
- background-color: #f8f9fa;
52
- padding: 20px;
53
- border-radius: 10px;
54
- box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
55
- margin-bottom: 20px;
56
- }
57
- .prompt {
58
- font-size: 16px;
59
- margin-bottom: 10px;
60
- }
61
- .response {
62
- font-size: 18px;
63
- font-style: italic;
64
- color: #666;
65
- }
66
- .input-container input[type="text"] {
67
- width: 100%;
68
- padding: 10px;
69
- font-size: 16px;
70
- border-radius: 5px;
71
- border: 1px solid #ccc;
72
- }
73
- .input-container input[type="text"]:focus {
74
- outline: none;
75
- border-color: #4d90fe;
76
- }
77
- </style>
78
- """
79
 
80
- def custom_interface():
81
- return """
82
- <div class="container">
83
- <div class="title">Nova V2</div>
84
- <div class="input-container">
85
- <div class="prompt">User Prompt:</div>
86
- <input type="text" id="user-prompt">
87
- </div>
88
- <div class="input-container">
89
- <div class="prompt">Chat History:</div>
90
- <textarea id="chat-history" rows="4"></textarea>
91
- </div>
92
- <div class="input-container">
93
- <button onclick="handleSubmit()" style="background-color: #4CAF50; color: white; padding: 14px 20px; margin-top: 10px; border: none; border-radius: 5px; cursor: pointer;">Generate Response</button>
94
- </div>
95
- <div class="response" id="response"></div>
96
- </div>
97
- <script>
98
- function handleSubmit() {
99
- var userPrompt = document.getElementById('user-prompt').value;
100
- var chatHistory = document.getElementById('chat-history').value;
101
- var responseContainer = document.getElementById('response');
102
- responseContainer.innerHTML = "Loading...";
103
- var xhr = new XMLHttpRequest();
104
- xhr.open('POST', '/predict');
105
- xhr.setRequestHeader('Content-Type', 'application/json');
106
- xhr.onload = function() {
107
- if (xhr.status === 200) {
108
- responseContainer.innerHTML = xhr.responseText;
109
- } else {
110
- responseContainer.innerHTML = 'Error: ' + xhr.statusText;
111
- }
112
- };
113
- xhr.send(JSON.stringify({prompt: userPrompt, history: chatHistory}));
114
- }
115
- </script>
116
- """
117
 
118
- gr.Interface(
119
- generate,
120
- inputs=["text", "text", "text", "text", "text"],
121
- outputs="text",
122
- title="Nova V2",
123
- examples=[
124
- ["Hello!", "Hi there!", "What are you doing?", "Nothing much, just chatting with you.", "How are you today?"],
125
- ],
126
- css=style(),
127
- allow_screenshot=False,
128
- capture_session=True
129
- ).launch(share=True, debug=True)
 
38
  yield output
39
  return output
40
 
41
+ additional_inputs=[
42
+ gr.Slider(
43
+ label="temperature",
44
+ value=0.9,
45
+ minimum=0.0,
46
+ maximum=1.0,
47
+ step=0.05,
48
+ interactive=True,
49
+ info="Higher values generate more diverse outputs",
50
+ ),
51
+ gr.Slider(
52
+ label="max_new_tokens",
53
+ value=256,
54
+ minimum=1,
55
+ maximum=2048,
56
+ step=1,
57
+ interactive=True,
58
+ info="Higher values allows for longer answers",
59
+ )
60
+ ]
61
+
62
+ mychatbot = gr.Chatbot(
63
+ avatar_images=["./user.png", "./botm.png"], bubble_full_width=False, show_label=False, show_copy_button=True, likeable=True,)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
64
 
65
+ demo = gr.ChatInterface(fn=generate,
66
+ chatbot=mychatbot,
67
+ title="Nova V2",
68
+ additional_inputs=additional_inputs,
69
+ retry_btn=None,
70
+ undo_btn=None
71
+ )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
72
 
73
+ demo.queue().launch() remove additional inputs and add a beautiful ui