Spaces:
Paused
Paused
Commit
·
0d283e9
1
Parent(s):
bdf7ce9
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,80 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from ask import askQuestion, getBrains
|
3 |
+
|
4 |
+
# abd="#f9fafe"
|
5 |
+
# abd="6469ff"
|
6 |
+
|
7 |
+
|
8 |
+
bg_color = "#c5dde0"
|
9 |
+
s_color = "#1d2230"
|
10 |
+
mycss = """
|
11 |
+
.gradio-container {{background-color: {bgcolor}}}
|
12 |
+
#title {{margin-top:33%;margin-bottom:25px;display:flex;justify-content:center;align-items:center}}
|
13 |
+
#title h1 {{font-weight:900;color:{scolor}}}
|
14 |
+
#advanced {{font-weight:600;background-color:#ffffff}}
|
15 |
+
#secondrow {{padding:0 6%;gap:30px}}
|
16 |
+
|
17 |
+
#name {{background-color: {bgcolor};border-style:none;border-width:0;box-shadow:none;padding-left:0;padding-right:0}}
|
18 |
+
#name .svelte-1gfkn6j {{background-color:{bgcolor};color:{scolor};font-size:18px}}
|
19 |
+
|
20 |
+
|
21 |
+
#question {{background-color: {bgcolor};border-style:none; !important;box-shadow:none !important;padding-left:0;padding-right:0}}
|
22 |
+
#question span {{background-color:{bgcolor};color:{scolor};font-size:18px}}
|
23 |
+
|
24 |
+
#output {{background-color: {bgcolor};border-style:none;border-width:0;box-shadow:none}}
|
25 |
+
#output span {{background-color:{bgcolor};color:{scolor};font-size:18px}}
|
26 |
+
|
27 |
+
#temp span {{background-color:#ffffff;color:{scolor}}}
|
28 |
+
#temp input {{accent-color:{scolor}}}
|
29 |
+
#tokens span {{background-color:#ffffff;color:{scolor}}}
|
30 |
+
#tokens input {{accent-color:{scolor}}}
|
31 |
+
|
32 |
+
#button {{background-color:{scolor};color:#ffffff;margin-top:15px}}
|
33 |
+
"""
|
34 |
+
formatted_css = mycss.format(bgcolor=bg_color, scolor=s_color)
|
35 |
+
|
36 |
+
|
37 |
+
def handleSubmit(brain_name, question, temperature, maxTokens):
|
38 |
+
if (brain_name == "" and question == ""):
|
39 |
+
return "Please select Brain Name & Enter Question"
|
40 |
+
if (brain_name == ""):
|
41 |
+
return "Please select Brain Name"
|
42 |
+
if (question == ""):
|
43 |
+
return "Please Enter Question"
|
44 |
+
return askQuestion(brain_name, question, temperature, maxTokens)
|
45 |
+
|
46 |
+
|
47 |
+
with gr.Blocks(theme=gr.themes.Soft(), css=formatted_css) as block_demo:
|
48 |
+
with gr.Row(elem_id="first"):
|
49 |
+
|
50 |
+
with gr.Column():
|
51 |
+
gr.Markdown(
|
52 |
+
"""
|
53 |
+
# Ask Brain!
|
54 |
+
""", elem_id="title")
|
55 |
+
|
56 |
+
with gr.Row(elem_id="secondrow"):
|
57 |
+
|
58 |
+
with gr.Column(scale=1, elem_id="inputsCol"):
|
59 |
+
|
60 |
+
brain_name = gr.Dropdown(
|
61 |
+
label="Brain Name", choices=getBrains(), elem_id="name")
|
62 |
+
question = gr.Textbox(
|
63 |
+
label="Question", lines=2, elem_id="question")
|
64 |
+
|
65 |
+
with gr.Accordion(label="Advance Options", open=False, elem_id="advanced") as a:
|
66 |
+
temperature = gr.Slider(
|
67 |
+
minimum=0.1, maximum=1.0, step=0.1, value=0.5, label="Temperature", elem_id="temp")
|
68 |
+
maxTokens = gr.Slider(minimum=500, maximum=2000,
|
69 |
+
step=100, value=1000, label="Max Tokens", elem_id="tokens")
|
70 |
+
|
71 |
+
submit_button = gr.Button(label="Submit", elem_id="button")
|
72 |
+
|
73 |
+
with gr.Column(scale=1, elem_id="outputCol",):
|
74 |
+
output_text = gr.TextArea(
|
75 |
+
label="Brain Output", lines=14, elem_id="output").style(show_copy_button=True)
|
76 |
+
|
77 |
+
submit_button.click(
|
78 |
+
handleSubmit, [brain_name, question, temperature, maxTokens], output_text)
|
79 |
+
|
80 |
+
block_demo.launch(show_api=False)
|