Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -7,8 +7,8 @@ from models import (
|
|
| 7 |
load_question_answering_model,
|
| 8 |
load_text_generation_model,
|
| 9 |
load_ner_model,
|
| 10 |
-
load_text_classification_model
|
| 11 |
-
load_text_to_sql_model
|
| 12 |
)
|
| 13 |
|
| 14 |
# Title and Description for your app
|
|
@@ -26,7 +26,6 @@ To make powerful AI models accessible, understandable, and usable for everyone t
|
|
| 26 |
• **Text Generation:** Create new text from prompts.
|
| 27 |
• **Named Entity Recognition:** Identify people, organizations, locations, etc.
|
| 28 |
• **Zero-Shot Classification:** Categorize text without pre-training.
|
| 29 |
-
• **Text to SQL:** Convert natural language to SQL queries.
|
| 30 |
**⚠️ Important Limitations:**
|
| 31 |
• **Summarization Length:** Works best with texts between **50 and 500 words**. Longer texts are automatically truncated.
|
| 32 |
• **Processing Speed:** Hosted on free-tier CPU hardware. Processing may take 10-30 seconds.
|
|
@@ -42,7 +41,6 @@ qa_pipeline = load_question_answering_model()
|
|
| 42 |
textgen_pipeline = load_text_generation_model()
|
| 43 |
ner_pipeline = load_ner_model()
|
| 44 |
classify_pipeline = load_text_classification_model()
|
| 45 |
-
text_to_sql_pipeline = load_text_to_sql_model()
|
| 46 |
|
| 47 |
def process_text(input_text, mode, context=None, candidate_labels=None):
|
| 48 |
"""The Conductor: routes input to the correct specialist model."""
|
|
@@ -142,16 +140,6 @@ def process_text(input_text, mode, context=None, candidate_labels=None):
|
|
| 142 |
except Exception as e:
|
| 143 |
return f"❌ Classification error: {str(e)}"
|
| 144 |
|
| 145 |
-
# Handle Text to SQL
|
| 146 |
-
elif mode == "Text to SQL":
|
| 147 |
-
try:
|
| 148 |
-
# Format the input for the SQL model
|
| 149 |
-
sql_input = f"Translate English to SQL: {input_text}"
|
| 150 |
-
result = text_to_sql_pipeline(sql_input, max_length=128)
|
| 151 |
-
return f"🗃️ **Generated SQL Query:**\n\n```sql\n{result[0]['generated_text']}\n```"
|
| 152 |
-
except Exception as e:
|
| 153 |
-
return f"❌ Text to SQL error: {str(e)}"
|
| 154 |
-
|
| 155 |
# Handle any other mode that might be added in the future
|
| 156 |
else:
|
| 157 |
return "Selected mode is not yet implemented."
|
|
@@ -172,8 +160,7 @@ with gr.Blocks(title=TITLE, css=".gradio-container {max-width: 800px; margin: au
|
|
| 172 |
"Question Answering",
|
| 173 |
"Text Generation",
|
| 174 |
"Named Entity Recognition",
|
| 175 |
-
"Zero-Shot Classification"
|
| 176 |
-
"Text to SQL"
|
| 177 |
],
|
| 178 |
label="🟰 Processing Mode",
|
| 179 |
value="Sentiment Analysis"
|
|
@@ -216,8 +203,7 @@ with gr.Blocks(title=TITLE, css=".gradio-container {max-width: 800px; margin: au
|
|
| 216 |
["What is the capital of France?", "Question Answering", "France is a country in Europe. Paris is the capital city of France.", None],
|
| 217 |
["Once upon a time in a land far, far away", "Text Generation", None, None],
|
| 218 |
["Apple Inc. was founded by Steve Jobs in Cupertino, California.", "Named Entity Recognition", None, None],
|
| 219 |
-
["The new smartphone has a great camera and long battery life", "Zero-Shot Classification", None, "technology, photography, travel"]
|
| 220 |
-
["Find all customers from California", "Text to SQL", None, None]
|
| 221 |
],
|
| 222 |
inputs=[input_text, mode, context, candidate_labels],
|
| 223 |
outputs=output_text,
|
|
|
|
| 7 |
load_question_answering_model,
|
| 8 |
load_text_generation_model,
|
| 9 |
load_ner_model,
|
| 10 |
+
load_text_classification_model
|
| 11 |
+
# Removed: load_text_to_sql_model
|
| 12 |
)
|
| 13 |
|
| 14 |
# Title and Description for your app
|
|
|
|
| 26 |
• **Text Generation:** Create new text from prompts.
|
| 27 |
• **Named Entity Recognition:** Identify people, organizations, locations, etc.
|
| 28 |
• **Zero-Shot Classification:** Categorize text without pre-training.
|
|
|
|
| 29 |
**⚠️ Important Limitations:**
|
| 30 |
• **Summarization Length:** Works best with texts between **50 and 500 words**. Longer texts are automatically truncated.
|
| 31 |
• **Processing Speed:** Hosted on free-tier CPU hardware. Processing may take 10-30 seconds.
|
|
|
|
| 41 |
textgen_pipeline = load_text_generation_model()
|
| 42 |
ner_pipeline = load_ner_model()
|
| 43 |
classify_pipeline = load_text_classification_model()
|
|
|
|
| 44 |
|
| 45 |
def process_text(input_text, mode, context=None, candidate_labels=None):
|
| 46 |
"""The Conductor: routes input to the correct specialist model."""
|
|
|
|
| 140 |
except Exception as e:
|
| 141 |
return f"❌ Classification error: {str(e)}"
|
| 142 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 143 |
# Handle any other mode that might be added in the future
|
| 144 |
else:
|
| 145 |
return "Selected mode is not yet implemented."
|
|
|
|
| 160 |
"Question Answering",
|
| 161 |
"Text Generation",
|
| 162 |
"Named Entity Recognition",
|
| 163 |
+
"Zero-Shot Classification"
|
|
|
|
| 164 |
],
|
| 165 |
label="🟰 Processing Mode",
|
| 166 |
value="Sentiment Analysis"
|
|
|
|
| 203 |
["What is the capital of France?", "Question Answering", "France is a country in Europe. Paris is the capital city of France.", None],
|
| 204 |
["Once upon a time in a land far, far away", "Text Generation", None, None],
|
| 205 |
["Apple Inc. was founded by Steve Jobs in Cupertino, California.", "Named Entity Recognition", None, None],
|
| 206 |
+
["The new smartphone has a great camera and long battery life", "Zero-Shot Classification", None, "technology, photography, travel"]
|
|
|
|
| 207 |
],
|
| 208 |
inputs=[input_text, mode, context, candidate_labels],
|
| 209 |
outputs=output_text,
|