Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,9 +1,9 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
-
# Load models (optimized for performance)
|
| 5 |
code_analyzer = pipeline("text-classification", model="microsoft/codebert-base")
|
| 6 |
-
nlp_model = pipeline("text2text-generation", model="google/flan-t5-
|
| 7 |
|
| 8 |
# Code Review Function
|
| 9 |
def analyze_code(code):
|
|
@@ -18,12 +18,15 @@ def validate_metadata(metadata):
|
|
| 18 |
return "No metadata provided.", "", ""
|
| 19 |
return "Field", "Unused field detected", "Remove it to improve performance"
|
| 20 |
|
| 21 |
-
# Natural Language Processor
|
| 22 |
def process_nlp_query(query):
|
| 23 |
if not query.strip():
|
| 24 |
return "No query provided."
|
| 25 |
-
|
| 26 |
-
|
|
|
|
|
|
|
|
|
|
| 27 |
|
| 28 |
# Gradio UI
|
| 29 |
with gr.Blocks() as demo:
|
|
@@ -47,7 +50,7 @@ with gr.Blocks() as demo:
|
|
| 47 |
|
| 48 |
with gr.Tab("Ask AI (Natural Language)"):
|
| 49 |
query_input = gr.Textbox(label="Your question", lines=2, placeholder="e.g. How to optimize SOQL?")
|
| 50 |
-
response_output = gr.Textbox(label="AI Response")
|
| 51 |
nlp_button = gr.Button("Ask")
|
| 52 |
nlp_button.click(process_nlp_query, inputs=query_input, outputs=response_output)
|
| 53 |
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
+
# Load models (optimized for performance and response quality)
|
| 5 |
code_analyzer = pipeline("text-classification", model="microsoft/codebert-base")
|
| 6 |
+
nlp_model = pipeline("text2text-generation", model="google/flan-t5-large") # Upgraded
|
| 7 |
|
| 8 |
# Code Review Function
|
| 9 |
def analyze_code(code):
|
|
|
|
| 18 |
return "No metadata provided.", "", ""
|
| 19 |
return "Field", "Unused field detected", "Remove it to improve performance"
|
| 20 |
|
| 21 |
+
# Natural Language Processor with better prompt formatting
|
| 22 |
def process_nlp_query(query):
|
| 23 |
if not query.strip():
|
| 24 |
return "No query provided."
|
| 25 |
+
|
| 26 |
+
# Add prompt formatting to help the model generate better answers
|
| 27 |
+
prompt = f"Answer the following software development question in detail:\n{query}"
|
| 28 |
+
result = nlp_model(prompt, max_length=150, do_sample=False)
|
| 29 |
+
return result[0]["generated_text"].strip()
|
| 30 |
|
| 31 |
# Gradio UI
|
| 32 |
with gr.Blocks() as demo:
|
|
|
|
| 50 |
|
| 51 |
with gr.Tab("Ask AI (Natural Language)"):
|
| 52 |
query_input = gr.Textbox(label="Your question", lines=2, placeholder="e.g. How to optimize SOQL?")
|
| 53 |
+
response_output = gr.Textbox(label="AI Response", lines=4)
|
| 54 |
nlp_button = gr.Button("Ask")
|
| 55 |
nlp_button.click(process_nlp_query, inputs=query_input, outputs=response_output)
|
| 56 |
|