Spaces:
Build error
Build error
| import gradio as gr | |
| from transformers import AutoTokenizer, AutoModel | |
| import torch | |
| import json | |
| # Load the tokenizer | |
| model_name = "TuringsSolutions/TechLegalV1" | |
| tokenizer = AutoTokenizer.from_pretrained(model_name) | |
| # Load adapter configuration manually | |
| adapter_config_path = "https://huggingface.co/TuringsSolutions/TechLegalV1/resolve/main/adapter_config.json" | |
| adapter_model_path = "https://huggingface.co/TuringsSolutions/TechLegalV1/resolve/main/adapter_model.safetensors" | |
| with open(adapter_config_path, 'r') as f: | |
| adapter_config = json.load(f) | |
| # Initialize the model with the adapter configuration | |
| model = AutoModel.from_pretrained(model_name, trust_remote_code=True) | |
| # Load adapter weights | |
| model.load_adapter(adapter_model_path, config=adapter_config) | |
| # Function to make predictions | |
| def predict(text): | |
| inputs = tokenizer(text, return_tensors="pt") | |
| with torch.no_grad(): | |
| outputs = model(**inputs) | |
| return outputs.last_hidden_state.mean(dim=1).squeeze().tolist() | |
| # Create a Gradio interface | |
| iface = gr.Interface( | |
| fn=predict, | |
| inputs=gr.inputs.Textbox(lines=2, placeholder="Enter text here..."), | |
| outputs="json", | |
| title="Tech Legal Model", | |
| description="A model for analyzing tech legal documents." | |
| ) | |
| # Launch the interface | |
| if __name__ == "__main__": | |
| iface.launch() | |