Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
|
| 4 |
+
# Load a language model for analyzing text quality
|
| 5 |
+
nlp_model = pipeline("text-classification", model="roberta-large-mnli")
|
| 6 |
+
|
| 7 |
+
# Function to analyze prompt
|
| 8 |
+
|
| 9 |
+
def analyze_prompt(prompt):
|
| 10 |
+
# Simple analysis by length and keyword presence
|
| 11 |
+
score = len(prompt.split()) / 10
|
| 12 |
+
feedback = "Try to use more descriptive words and specific details."
|
| 13 |
+
|
| 14 |
+
# Generate alternative prompts
|
| 15 |
+
improved_prompts = [
|
| 16 |
+
prompt + " with cinematic lighting",
|
| 17 |
+
prompt + " ultra-realistic style",
|
| 18 |
+
prompt + " high detail, sharp focus"
|
| 19 |
+
]
|
| 20 |
+
|
| 21 |
+
# Limit score to a 1-10 scale
|
| 22 |
+
score = min(max(score, 1), 10)
|
| 23 |
+
return score, feedback, improved_prompts
|
| 24 |
+
|
| 25 |
+
# Gradio Interface
|
| 26 |
+
def main_interface():
|
| 27 |
+
with gr.Blocks() as demo:
|
| 28 |
+
gr.Markdown("# Interactive Prompt Learning Tool")
|
| 29 |
+
prompt_input = gr.Textbox(label="Enter your prompt for AI image generation")
|
| 30 |
+
submit_button = gr.Button("Analyze Prompt")
|
| 31 |
+
|
| 32 |
+
with gr.Row():
|
| 33 |
+
score_output = gr.Number(label="Prompt Quality Score (1-10)")
|
| 34 |
+
feedback_output = gr.Textbox(label="Feedback for Improvement")
|
| 35 |
+
|
| 36 |
+
improved_output = gr.Textbox(label="Improved Prompt Suggestions", lines=3)
|
| 37 |
+
|
| 38 |
+
submit_button.click(
|
| 39 |
+
analyze_prompt,
|
| 40 |
+
inputs=prompt_input,
|
| 41 |
+
outputs=[score_output, feedback_output, improved_output]
|
| 42 |
+
)
|
| 43 |
+
|
| 44 |
+
demo.launch()
|
| 45 |
+
|
| 46 |
+
# Launch the app
|
| 47 |
+
if __name__ == "__main__":
|
| 48 |
+
main_interface()
|