Spaces:
Sleeping
Sleeping
TuringsSolutions
commited on
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
3 |
+
|
4 |
+
# Load tokenizer and model
|
5 |
+
tokenizer = AutoTokenizer.from_pretrained("TuringsSolutions/LegalGemmaV1", trust_remote_code=True)
|
6 |
+
model = AutoModelForCausalLM.from_pretrained("TuringsSolutions/LegalGemmaV1", trust_remote_code=True)
|
7 |
+
|
8 |
+
def predict(prompt, temperature, max_tokens):
|
9 |
+
inputs = tokenizer(prompt, return_tensors="pt")
|
10 |
+
outputs = model.generate(
|
11 |
+
**inputs,
|
12 |
+
max_new_tokens=max_tokens,
|
13 |
+
temperature=temperature
|
14 |
+
)
|
15 |
+
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
16 |
+
return response
|
17 |
+
|
18 |
+
# Create Gradio interface
|
19 |
+
iface = gr.Interface(
|
20 |
+
fn=predict,
|
21 |
+
inputs=[
|
22 |
+
gr.Textbox(lines=2, placeholder="Enter your prompt here..."),
|
23 |
+
gr.Slider(minimum=0.1, maximum=1.0, value=0.7, label="Temperature"),
|
24 |
+
gr.Slider(minimum=10, maximum=200, value=50, step=10, label="Number of Output Tokens")
|
25 |
+
],
|
26 |
+
outputs="text",
|
27 |
+
title="Gemma 2 2B Law Case Management Model",
|
28 |
+
description="A model to assist with law case management. Adjust the temperature and number of output tokens as needed."
|
29 |
+
)
|
30 |
+
|
31 |
+
# Launch the Gradio app
|
32 |
+
iface.launch()
|