fkalpana commited on
Commit
b503163
1 Parent(s): 2e4c29b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -12
app.py CHANGED
@@ -1,21 +1,32 @@
1
  import gradio as gr
2
- from transformers import pipeline
3
 
4
- # Initialize the translation pipeline with a pre-trained model
5
- translator = pipeline("translation_en_to_fr", model="t5-small")
 
6
 
7
- def translate(text):
8
- # Translate the input text from English to French
9
- result = translator(text, max_length=512)
10
- return result[0]['translation_text']
 
 
 
 
 
 
 
 
 
 
11
 
12
  # Define the Gradio interface
13
  iface = gr.Interface(
14
- fn=translate,
15
- inputs=gr.Textbox(lines=2, placeholder="Enter English text here..."),
16
- outputs=gr.Textbox(), # Updated for Gradio version 4.0
17
- title="English to French Translation",
18
- description="This app uses the T5 model to translate English text to French. Type some text and press submit."
19
  )
20
 
21
  # Launch the app
 
1
  import gradio as gr
2
+ from transformers import T5Tokenizer, T5ForConditionalGeneration
3
 
4
+ # Load the tokenizer and model
5
+ tokenizer = T5Tokenizer.from_pretrained('t5-small')
6
+ model = T5ForConditionalGeneration.from_pretrained('t5-small')
7
 
8
+ def generate_sql(question):
9
+ # Format the question for the model if needed. For example:
10
+ # input_text = f"translate English to SQL: {question}"
11
+ input_text = f"{question}" # Directly use the question if the model is fine-tuned for SQL generation
12
+
13
+ # Tokenize the input text
14
+ input_ids = tokenizer.encode(input_text, return_tensors="pt")
15
+
16
+ # Generate the output sequence
17
+ output_ids = model.generate(input_ids, max_length=512, num_beams=5)[0]
18
+
19
+ # Decode the generated ids to get the SQL query
20
+ sql_query = tokenizer.decode(output_ids, skip_special_tokens=True)
21
+ return sql_query
22
 
23
  # Define the Gradio interface
24
  iface = gr.Interface(
25
+ fn=generate_sql,
26
+ inputs=gr.Textbox(lines=2, placeholder="Enter your question here..."),
27
+ outputs=gr.Textbox(),
28
+ title="Natural Language to SQL",
29
+ description="This app uses a Seq2Seq model to generate SQL queries from natural language questions."
30
  )
31
 
32
  # Launch the app