File size: 1,343 Bytes
928dc0a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# This is a basic Hugging Face Space using Gradio to beautify and complete sentences.
# You can deploy this in your Space (https://huggingface.co/spaces)

import gradio as gr
from transformers import pipeline

# Load a free instruction-following model
pipe = pipeline("text-generation", model="mistralai/Mistral-7B-Instruct-v0.1", device_map="auto")

def complete_sentence(input_text):
    if not input_text.strip():
        return "No input provided."

    prompt = f"Beautify and complete the following sentence:
@@@{input_text}###"

    try:
        output = pipe(prompt, max_new_tokens=100, do_sample=True, temperature=0.7)
        generated = output[0]['generated_text']

        # Extract text between markers
        start = generated.find("@@@")
        end = generated.find("###", start)
        if start != -1 and end != -1:
            beautified = generated[start+3:end].strip()
            return beautified
        else:
            return generated.strip()

    except Exception as e:
        return f"Error: {str(e)}"

iface = gr.Interface(
    fn=complete_sentence,
    inputs=gr.Textbox(label="Enter your sentence"),
    outputs=gr.Textbox(label="Completed sentence"),
    title="Sentence Beautifier (Mistral 7B)",
    description="Enter a raw or incomplete sentence. The AI will beautify and complete it."
)

iface.launch()