mms10 / app
badru's picture
Create app
928dc0a verified
# 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()