Spaces:
Runtime error
Runtime error
Upload folder using huggingface_hub
Browse files- README.md +2 -8
- gradio_app.py +70 -0
README.md
CHANGED
@@ -1,12 +1,6 @@
|
|
1 |
---
|
2 |
-
title:
|
3 |
-
|
4 |
-
colorFrom: green
|
5 |
-
colorTo: red
|
6 |
sdk: gradio
|
7 |
sdk_version: 3.44.4
|
8 |
-
app_file: app.py
|
9 |
-
pinned: false
|
10 |
---
|
11 |
-
|
12 |
-
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
1 |
---
|
2 |
+
title: votum-demo
|
3 |
+
app_file: gradio_app.py
|
|
|
|
|
4 |
sdk: gradio
|
5 |
sdk_version: 3.44.4
|
|
|
|
|
6 |
---
|
|
|
|
gradio_app.py
ADDED
@@ -0,0 +1,70 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# %%
|
2 |
+
|
3 |
+
from threading import Thread
|
4 |
+
|
5 |
+
import gradio as gr
|
6 |
+
# import torch
|
7 |
+
from text_generation import Client, InferenceAPIClient
|
8 |
+
from transformers import (AutoModelForCausalLM, AutoModelForSeq2SeqLM,
|
9 |
+
AutoTokenizer, BitsAndBytesConfig,
|
10 |
+
TextIteratorStreamer)
|
11 |
+
|
12 |
+
client = Client("http://20.83.177.108:8080")
|
13 |
+
|
14 |
+
|
15 |
+
# text = ""
|
16 |
+
# for response in client.generate_stream("What is Deep Learning?", max_new_tokens=20):
|
17 |
+
# if not response.token.special:
|
18 |
+
# text += response.token.text
|
19 |
+
# print(text)
|
20 |
+
|
21 |
+
|
22 |
+
|
23 |
+
def run_generation(user_text, top_p, temperature, top_k, max_new_tokens):
|
24 |
+
# Get the model and tokenizer, and tokenize the user text.
|
25 |
+
user_text = f"""You are an expert legal assistant with extensive knowledge about Indian law. Your task is to respond to the given query in a consice and factually correct manner. Also mention the relevant sections of the law wherever applicable.
|
26 |
+
### Input: {user_text}
|
27 |
+
### Response: """
|
28 |
+
|
29 |
+
text = ""
|
30 |
+
for response in client.generate_stream(user_text, max_new_tokens=max_new_tokens,repetition_penalty=1.05):
|
31 |
+
if not response.token.special:
|
32 |
+
text += response.token.text
|
33 |
+
yield text
|
34 |
+
|
35 |
+
return text
|
36 |
+
|
37 |
+
|
38 |
+
def reset_textbox():
|
39 |
+
return gr.update(value='')
|
40 |
+
|
41 |
+
|
42 |
+
with gr.Blocks() as demo:
|
43 |
+
with gr.Row():
|
44 |
+
with gr.Column(scale=4):
|
45 |
+
user_text = gr.Textbox(
|
46 |
+
placeholder="What is the punishment for taking dowry. explain in detail.",
|
47 |
+
label="Question"
|
48 |
+
)
|
49 |
+
model_output = gr.Textbox(label="AI Response", lines=10, interactive=False)
|
50 |
+
button_submit = gr.Button(value="Submit")
|
51 |
+
|
52 |
+
with gr.Column(scale=1):
|
53 |
+
max_new_tokens = gr.Slider(
|
54 |
+
minimum=1, maximum=1000, value=250, step=10, interactive=True, label="Max New Tokens",
|
55 |
+
)
|
56 |
+
top_p = gr.Slider(
|
57 |
+
minimum=0.05, maximum=1.0, value=0.95, step=0.05, interactive=True, label="Top-p (nucleus sampling)",
|
58 |
+
)
|
59 |
+
top_k = gr.Slider(
|
60 |
+
minimum=1, maximum=50, value=50, step=1, interactive=True, label="Top-k",
|
61 |
+
)
|
62 |
+
temperature = gr.Slider(
|
63 |
+
minimum=0.1, maximum=1.0, value=0.8, step=0.1, interactive=True, label="Temperature",
|
64 |
+
)
|
65 |
+
|
66 |
+
user_text.submit(run_generation, [user_text, top_p, temperature, top_k, max_new_tokens], model_output)
|
67 |
+
button_submit.click(run_generation, [user_text, top_p, temperature, top_k, max_new_tokens], model_output)
|
68 |
+
|
69 |
+
demo.queue(max_size=32).launch(enable_queue=True,share=True)
|
70 |
+
|