Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 3 |
+
import torch
|
| 4 |
+
|
| 5 |
+
model_id = "srujanamadiraju/merged-nl-sql-gemma2b" # your uploaded model
|
| 6 |
+
|
| 7 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
| 8 |
+
model = AutoModelForCausalLM.from_pretrained(model_id, torch_dtype=torch.float16, device_map="auto")
|
| 9 |
+
|
| 10 |
+
def generate_sql(prompt):
|
| 11 |
+
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
|
| 12 |
+
output = model.generate(**inputs, max_new_tokens=128, temperature=0.2, do_sample=True)
|
| 13 |
+
return tokenizer.decode(output[0], skip_special_tokens=True)
|
| 14 |
+
|
| 15 |
+
interface = gr.Interface(fn=generate_sql, inputs="text", outputs="text",
|
| 16 |
+
title="Gemma NL2SQL API",
|
| 17 |
+
description="Convert natural language to SQL with merged Gemma model")
|
| 18 |
+
|
| 19 |
+
interface.launch()
|