Spaces:
Sleeping
Sleeping
Dinethnethsara2010
commited on
Commit
•
56d6d11
1
Parent(s):
3286a2f
Update app.py
Browse files
app.py
CHANGED
@@ -38,92 +38,36 @@ def generate(
|
|
38 |
yield output
|
39 |
return output
|
40 |
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
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 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
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 |
-
|
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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|