CoolFace
Apppublic

B1air/fantasyeditor

sourceHugging Faceupdated 2y agoView on Hugging Face
0likes
app.py38 linesDownload Raw Back to root
1import gradio as gr2from transformers import pipeline3 4# Use a different model if desired5model = pipeline("text-generation", model="distilgpt2")  # Or another model of your choice6 7def suggest_changes(text):8    # Enhanced prompt focused on generating clear suggestions9    prompt = (10        "You are a professional writing assistant with expertise in editing and improving prose. "11        "Review the following text and provide exactly three specific suggestions to improve it. "12        "Your suggestions should focus on actionable edits without unnecessary commentary. "13        "The format for your suggestions should be as follows:\n"14        "1. [Grammar improvement]\n"15        "2. [Clarity enhancement]\n"16        "3. [Prose enrichment]\n\n"17        f"Text: {text}\n\n"18        "Please provide your suggestions in bullet point format and avoid any additional explanations."19    )20    21    # Generate suggestions22    suggestions = model(prompt, max_length=200, num_return_sequences=1)[0]['generated_text']23    24    # Clean up the output to ensure it only contains the suggestions25    return suggestions.split("Text:")[-1].strip()26 27# Create Gradio interface28interface = gr.Interface(29    fn=suggest_changes,30    inputs="textbox",31    outputs="textbox",32    title="Fantasy Story Editor",33    description="Paste your fantasy writing here for editing suggestions."34)35 36# Launch the app37interface.launch()38