Upload folder using huggingface_hub
Browse files
app.py
CHANGED
@@ -2,10 +2,12 @@ import gradio as gr
|
|
2 |
from transformers import pipeline
|
3 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
4 |
|
5 |
-
# Load the model
|
6 |
model_name = "AdaptLLM/law-LLM"
|
7 |
# model_name = "google/gemma-2b"
|
8 |
# model_name = "mistralai/Mistral-7B-v0.1"
|
|
|
|
|
9 |
tokenizer = AutoTokenizer.from_pretrained(model_name, use_fast=False)
|
10 |
model = AutoModelForCausalLM.from_pretrained(model_name)
|
11 |
|
@@ -33,16 +35,46 @@ def chat_interface(input_text):
|
|
33 |
response = tokenizer.decode(outputs[answer_start:], skip_special_tokens=True)
|
34 |
return response
|
35 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
|
37 |
-
# Create the Gradio interface
|
38 |
-
iface = gr.Interface(
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
# live=True # Enable live updates
|
45 |
-
)
|
46 |
|
47 |
# Launch the interface using Hugging Face Spaces
|
48 |
-
iface.launch(share=True)
|
|
|
2 |
from transformers import pipeline
|
3 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
4 |
|
5 |
+
# Load the model
|
6 |
model_name = "AdaptLLM/law-LLM"
|
7 |
# model_name = "google/gemma-2b"
|
8 |
# model_name = "mistralai/Mistral-7B-v0.1"
|
9 |
+
|
10 |
+
# Tokenizers usage
|
11 |
tokenizer = AutoTokenizer.from_pretrained(model_name, use_fast=False)
|
12 |
model = AutoModelForCausalLM.from_pretrained(model_name)
|
13 |
|
|
|
35 |
response = tokenizer.decode(outputs[answer_start:], skip_special_tokens=True)
|
36 |
return response
|
37 |
|
38 |
+
# Load the Gemma 2B model using the pipeline
|
39 |
+
gemma_2b_chatbot = pipeline("text2text-generation", model="google/gemma-2b")
|
40 |
+
|
41 |
+
# Load the law-LLM model using the pipeline
|
42 |
+
law_llm_chatbot = pipeline("text2text-generation", model="AdaptLLM/law-LLM")
|
43 |
+
|
44 |
+
# Define the chat function for Gemma 2B
|
45 |
+
def gemma_2b_chat(input_text):
|
46 |
+
response = gemma_2b_chatbot(input_text)[0]["generated_text"]
|
47 |
+
return response
|
48 |
+
|
49 |
+
# Define the chat function for law-LLM
|
50 |
+
def law_llm_chat(input_text):
|
51 |
+
response = law_llm_chatbot(input_text)[0]["generated_text"]
|
52 |
+
return response
|
53 |
+
|
54 |
+
|
55 |
+
# Create the Gradio interface for Gemma 2B
|
56 |
+
# gemma_2b_inputs = gr.inputs.Textbox(lines=2, label="User Input")
|
57 |
+
# gemma_2b_outputs = gr.outputs.Textbox(label="Chatbot Response")
|
58 |
+
# gemma_2b_interface = gr.Interface(fn=gemma_2b_chat, inputs=gemma_2b_inputs, outputs=gemma_2b_outputs)
|
59 |
+
|
60 |
+
# Create the Gradio interface for law-LLM
|
61 |
+
law_llm_inputs = gr.inputs.Textbox(lines=2, label="User Input")
|
62 |
+
law_llm_outputs = gr.outputs.Textbox(label="Chatbot Response")
|
63 |
+
law_llm_interface = gr.Interface(fn=law_llm_chat, inputs=law_llm_inputs, outputs=law_llm_outputs)
|
64 |
+
|
65 |
+
# Run the Gradio interfaces
|
66 |
+
# gemma_2b_interface.launch(share=True)
|
67 |
+
law_llm_interface.launch(share=True)
|
68 |
|
69 |
+
# Create the Gradio interface with tokenizers
|
70 |
+
# iface = gr.Interface(
|
71 |
+
# fn=chat_interface,
|
72 |
+
# inputs=gr.inputs.Textbox(lines=2, label="Input Text"),
|
73 |
+
# outputs=gr.outputs.Textbox(label="Output Text"),
|
74 |
+
# title="Chat Interface",
|
75 |
+
# description="Enter text and get a response using the LLM model",
|
76 |
# live=True # Enable live updates
|
77 |
+
# )
|
78 |
|
79 |
# Launch the interface using Hugging Face Spaces
|
80 |
+
# iface.launch(share=True)
|