Aaryaparikh commited on
Commit
a56e433
1 Parent(s): 807e081

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +65 -0
app.py ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import re
3
+ import pandas as pd
4
+ import numpy as np
5
+ import time
6
+ import torch
7
+ from transformers import T5Tokenizer, T5ForConditionalGeneration
8
+ # Streamlit app
9
+ st.title("Private Sample")
10
+ tokenizer = T5Tokenizer.from_pretrained('t5-small')
11
+
12
+ # Load the model
13
+ device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
14
+ model = T5ForConditionalGeneration.from_pretrained('cssupport/t5-small-awesome-text-to-sql')
15
+ model = model.to(device)
16
+ model.eval()
17
+
18
+ def generate_sql(input_prompt):
19
+ # Tokenize the input prompt
20
+ inputs = tokenizer(input_prompt, padding=True, truncation=True, return_tensors="pt").to(device)
21
+
22
+ # Forward pass
23
+ with torch.no_grad():
24
+ outputs = model.generate(**inputs, max_length=512)
25
+
26
+ # Decode the output IDs to a string (SQL query in this case)
27
+ generated_sql = tokenizer.decode(outputs[0], skip_special_tokens=True)
28
+
29
+ return generated_sql
30
+ prompt=st.text_input("Enter Prompt: ","get target from app saless")
31
+ button_clicked=st.button("Generate")
32
+ if button_clicked:
33
+ input_prompt = "tables:\n" + "CREATE TABLE AppDrug_allergy_dataset( Id,ExtraProperties,ConcurrencyStamp,CreationTime,CreatorId,LastModificationTime,LastModifierId,IsDeleted,DeleterId,DeletionTime,Drug_Name,Chemical_Structure,Immunogenecity,Individual_Sensitivity,Prior_Allergic_Reaction,Cross_Reactivity,Route_of_administration,Dose,Duration,Hypersensitivity_Reaction,Allergic) CREATE TABLE AppSaless( Id,ExtraProperties,ConcurrencyStamp,CreationTime, CreatorId,LastModificationTime,LastModifierId,IsDeleted,DeleterId,DeletionTime,Month,Target,Customers_,Revenue)" + "\n" +"query for:" + prompt
34
+ generated_sql = generate_sql(input_prompt)
35
+ print(f"The generated SQL query is: {generated_sql}")
36
+ # Test the function
37
+ #input_prompt = "tables:\n" + "CREATE TABLE Catalogs (date_of_latest_revision VARCHAR)" + "\n" +"query for: Find the dates on which more than one revisions were made."
38
+ #input_prompt = "tables:\n" + "CREATE TABLE table_22767 ( \"Year\" real, \"World\" real, \"Asia\" text, \"Africa\" text, \"Europe\" text, \"Latin America/Caribbean\" text, \"Northern America\" text, \"Oceania\" text )" + "\n" +"query for:what will the population of Asia be when Latin America/Caribbean is 783 (7.5%)?."
39
+ # input_prompt = "Retrieve the names of all employees who work in the IT department."
40
+
41
+
42
+ #OUTPUT: The generated SQL query is: SELECT student_id FROM students WHERE NOT student_id IN (SELECT student_id FROM student_course_attendance)
43
+
44
+ progress_bar = st.progress(0)
45
+ status_text = st.empty()
46
+ chart = st.line_chart(np.random.randn(10, 2))
47
+
48
+ for i in range(100):
49
+ # Update progress bar.
50
+ progress_bar.progress(i + 1)
51
+
52
+ new_rows = np.random.randn(10, 2)
53
+
54
+ # Update status text.
55
+ status_text.text(
56
+ 'The latest random number is: %s' % new_rows[-1, 1])
57
+
58
+ # Append data to the chart.
59
+ chart.add_rows(new_rows)
60
+
61
+ # Pretend we're doing some computation that takes time.
62
+ time.sleep(0.1)
63
+
64
+ status_text.text('Done!')
65
+ st.balloons()