yashMahajan
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,8 @@
|
|
1 |
import gradio as gr
|
2 |
-
from
|
3 |
|
4 |
-
client
|
|
|
5 |
|
6 |
def respond(
|
7 |
message,
|
@@ -24,26 +25,32 @@ def respond(
|
|
24 |
response = ""
|
25 |
|
26 |
# Get the model's response
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
response
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
|
|
|
|
|
|
40 |
|
41 |
yield response
|
42 |
|
|
|
|
|
|
|
|
|
43 |
demo = gr.ChatInterface(
|
44 |
respond,
|
45 |
additional_inputs=[
|
46 |
-
gr.Textbox(value="You are a knowledgeable assistant specializing in the Constitution of India. Answer only questions related to the Constitution. If you find that a question is not relevant, inform the user accordingly.", label="System message"),
|
47 |
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
|
48 |
gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
|
49 |
gr.Slider(
|
|
|
1 |
import gradio as gr
|
2 |
+
from gradio_client import Client
|
3 |
|
4 |
+
# Initialize the client with the new model
|
5 |
+
client = Client("nikravan/Bitnet-1B")
|
6 |
|
7 |
def respond(
|
8 |
message,
|
|
|
25 |
response = ""
|
26 |
|
27 |
# Get the model's response
|
28 |
+
try:
|
29 |
+
result = client.predict(
|
30 |
+
api_name="/chat",
|
31 |
+
messages=messages,
|
32 |
+
max_tokens=max_tokens,
|
33 |
+
temperature=temperature,
|
34 |
+
top_p=top_p
|
35 |
+
)
|
36 |
+
response = result['text'] # Adjust based on the actual output format
|
37 |
+
|
38 |
+
# Post-process the response to ensure relevance
|
39 |
+
if not is_constitution_related(response):
|
40 |
+
response = "Sorry, I can only answer questions related to the Constitution of India."
|
41 |
+
|
42 |
+
except Exception as e:
|
43 |
+
response = f"Error: {str(e)}"
|
44 |
|
45 |
yield response
|
46 |
|
47 |
+
def is_constitution_related(response):
|
48 |
+
# Perform a simple check to see if the response seems related to the Constitution
|
49 |
+
return "constitution" in response.lower() or "article" in response.lower()
|
50 |
+
|
51 |
demo = gr.ChatInterface(
|
52 |
respond,
|
53 |
additional_inputs=[
|
|
|
54 |
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
|
55 |
gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
|
56 |
gr.Slider(
|