Spaces:
Runtime error
Runtime error
on1onmangoes
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -8,10 +8,6 @@ HF_TOKEN = os.getenv("HF_TOKEN") # Replace with your actual token if not using
|
|
8 |
# Initialize the Gradio Client for the specified API
|
9 |
client = Client("on1onmangoes/CNIHUB10724v9", hf_token=HF_TOKEN)
|
10 |
|
11 |
-
# Authentication function
|
12 |
-
def login(username, password):
|
13 |
-
return username == "your_username" and password == "your_password" # Update with actual credentials
|
14 |
-
|
15 |
# Function to handle chat API call
|
16 |
def stream_chat_with_rag(message, client_name, system_prompt, num_retrieved_docs, num_docs_final, temperature, max_new_tokens, top_p, top_k, penalty):
|
17 |
response = client.predict(
|
@@ -54,95 +50,81 @@ with gr.Blocks() as app:
|
|
54 |
password_input = gr.Textbox(label="Password", placeholder="Enter your password", type="password")
|
55 |
|
56 |
with gr.Tab("Chat"):
|
57 |
-
chatbot = gr.Chatbot(
|
58 |
-
|
59 |
-
# Create an accordion for additional input parameters
|
60 |
-
additional_inputs_accordion = gr.Accordion(label="⚙️ Parameters", open=False, render=False)
|
61 |
-
|
62 |
-
with additional_inputs_accordion:
|
63 |
-
client_name_dropdown = gr.Dropdown(
|
64 |
-
label="Select Client",
|
65 |
-
choices=["rosariarossi", "bianchifiordaliso", "lorenzoverdi"],
|
66 |
-
value="rosariarossi",
|
67 |
-
render=False
|
68 |
-
)
|
69 |
-
system_prompt_input = gr.Textbox(
|
70 |
-
value="You are an expert assistant",
|
71 |
-
label="System Prompt",
|
72 |
-
render=False
|
73 |
-
)
|
74 |
-
num_retrieved_docs_slider = gr.Slider(
|
75 |
-
label="Number of Initial Documents to Retrieve",
|
76 |
-
minimum=1,
|
77 |
-
maximum=10,
|
78 |
-
step=1,
|
79 |
-
value=10,
|
80 |
-
render=False
|
81 |
-
)
|
82 |
-
num_docs_final_slider = gr.Slider(
|
83 |
-
label="Number of Final Documents to Retrieve",
|
84 |
-
minimum=1,
|
85 |
-
maximum=10,
|
86 |
-
step=1,
|
87 |
-
value=9,
|
88 |
-
render=False
|
89 |
-
)
|
90 |
-
temperature_slider = gr.Slider(
|
91 |
-
label="Temperature",
|
92 |
-
minimum=0.2,
|
93 |
-
maximum=1,
|
94 |
-
step=0.1,
|
95 |
-
value=0,
|
96 |
-
render=False
|
97 |
-
)
|
98 |
-
max_new_tokens_slider = gr.Slider(
|
99 |
-
label="Max New Tokens",
|
100 |
-
minimum=128,
|
101 |
-
maximum=8192,
|
102 |
-
step=1,
|
103 |
-
value=1024,
|
104 |
-
render=False
|
105 |
-
)
|
106 |
-
top_p_slider = gr.Slider(
|
107 |
-
label="Top P",
|
108 |
-
minimum=0.0,
|
109 |
-
maximum=1.0,
|
110 |
-
step=0.1,
|
111 |
-
value=1.0,
|
112 |
-
render=False
|
113 |
-
)
|
114 |
-
top_k_slider = gr.Slider(
|
115 |
-
label="Top K",
|
116 |
-
minimum=1,
|
117 |
-
maximum=20,
|
118 |
-
step=1,
|
119 |
-
value=20,
|
120 |
-
render=False
|
121 |
-
)
|
122 |
-
penalty_slider = gr.Slider(
|
123 |
-
label="Repetition Penalty",
|
124 |
-
minimum=0.0,
|
125 |
-
maximum=2.0,
|
126 |
-
step=0.1,
|
127 |
-
value=1.2,
|
128 |
-
render=False
|
129 |
-
)
|
130 |
-
|
131 |
chat_interface = gr.ChatInterface(
|
132 |
fn=stream_chat_with_rag,
|
133 |
chatbot=chatbot,
|
134 |
fill_height=True,
|
135 |
-
additional_inputs_accordion=
|
136 |
additional_inputs=[
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
146 |
],
|
147 |
)
|
148 |
|
|
|
8 |
# Initialize the Gradio Client for the specified API
|
9 |
client = Client("on1onmangoes/CNIHUB10724v9", hf_token=HF_TOKEN)
|
10 |
|
|
|
|
|
|
|
|
|
11 |
# Function to handle chat API call
|
12 |
def stream_chat_with_rag(message, client_name, system_prompt, num_retrieved_docs, num_docs_final, temperature, max_new_tokens, top_p, top_k, penalty):
|
13 |
response = client.predict(
|
|
|
50 |
password_input = gr.Textbox(label="Password", placeholder="Enter your password", type="password")
|
51 |
|
52 |
with gr.Tab("Chat"):
|
53 |
+
chatbot = gr.Chatbot() # Create a chatbot interface
|
54 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
55 |
chat_interface = gr.ChatInterface(
|
56 |
fn=stream_chat_with_rag,
|
57 |
chatbot=chatbot,
|
58 |
fill_height=True,
|
59 |
+
additional_inputs_accordion=gr.Accordion(label="⚙️ Parameters", open=False, render=False),
|
60 |
additional_inputs=[
|
61 |
+
gr.Dropdown(
|
62 |
+
['rosariarossi', 'bianchifiordaliso', 'lorenzoverdi'],
|
63 |
+
value="rosariarossi",
|
64 |
+
label="Select Client",
|
65 |
+
render=False,
|
66 |
+
),
|
67 |
+
gr.Textbox(
|
68 |
+
value="You are an expert assistant",
|
69 |
+
label="System Prompt",
|
70 |
+
render=False,
|
71 |
+
),
|
72 |
+
gr.Slider(
|
73 |
+
minimum=1,
|
74 |
+
maximum=10,
|
75 |
+
step=1,
|
76 |
+
value=10,
|
77 |
+
label="Number of Initial Documents to Retrieve",
|
78 |
+
render=False,
|
79 |
+
),
|
80 |
+
gr.Slider(
|
81 |
+
minimum=1,
|
82 |
+
maximum=10,
|
83 |
+
step=1,
|
84 |
+
value=9,
|
85 |
+
label="Number of Final Documents to Retrieve",
|
86 |
+
render=False,
|
87 |
+
),
|
88 |
+
gr.Slider(
|
89 |
+
minimum=0.2,
|
90 |
+
maximum=1,
|
91 |
+
step=0.1,
|
92 |
+
value=0,
|
93 |
+
label="Temperature",
|
94 |
+
render=False,
|
95 |
+
),
|
96 |
+
gr.Slider(
|
97 |
+
minimum=128,
|
98 |
+
maximum=8192,
|
99 |
+
step=1,
|
100 |
+
value=1024,
|
101 |
+
label="Max new tokens",
|
102 |
+
render=False,
|
103 |
+
),
|
104 |
+
gr.Slider(
|
105 |
+
minimum=0.0,
|
106 |
+
maximum=1.0,
|
107 |
+
step=0.1,
|
108 |
+
value=1.0,
|
109 |
+
label="Top P",
|
110 |
+
render=False,
|
111 |
+
),
|
112 |
+
gr.Slider(
|
113 |
+
minimum=1,
|
114 |
+
maximum=20,
|
115 |
+
step=1,
|
116 |
+
value=20,
|
117 |
+
label="Top K",
|
118 |
+
render=False,
|
119 |
+
),
|
120 |
+
gr.Slider(
|
121 |
+
minimum=0.0,
|
122 |
+
maximum=2.0,
|
123 |
+
step=0.1,
|
124 |
+
value=1.2,
|
125 |
+
label="Repetition Penalty",
|
126 |
+
render=False,
|
127 |
+
),
|
128 |
],
|
129 |
)
|
130 |
|