badru commited on
Commit
928dc0a
·
verified ·
1 Parent(s): ef78b36

Create app

Browse files
Files changed (1) hide show
  1. app +41 -0
app ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # This is a basic Hugging Face Space using Gradio to beautify and complete sentences.
2
+ # You can deploy this in your Space (https://huggingface.co/spaces)
3
+
4
+ import gradio as gr
5
+ from transformers import pipeline
6
+
7
+ # Load a free instruction-following model
8
+ pipe = pipeline("text-generation", model="mistralai/Mistral-7B-Instruct-v0.1", device_map="auto")
9
+
10
+ def complete_sentence(input_text):
11
+ if not input_text.strip():
12
+ return "No input provided."
13
+
14
+ prompt = f"Beautify and complete the following sentence:
15
+ @@@{input_text}###"
16
+
17
+ try:
18
+ output = pipe(prompt, max_new_tokens=100, do_sample=True, temperature=0.7)
19
+ generated = output[0]['generated_text']
20
+
21
+ # Extract text between markers
22
+ start = generated.find("@@@")
23
+ end = generated.find("###", start)
24
+ if start != -1 and end != -1:
25
+ beautified = generated[start+3:end].strip()
26
+ return beautified
27
+ else:
28
+ return generated.strip()
29
+
30
+ except Exception as e:
31
+ return f"Error: {str(e)}"
32
+
33
+ iface = gr.Interface(
34
+ fn=complete_sentence,
35
+ inputs=gr.Textbox(label="Enter your sentence"),
36
+ outputs=gr.Textbox(label="Completed sentence"),
37
+ title="Sentence Beautifier (Mistral 7B)",
38
+ description="Enter a raw or incomplete sentence. The AI will beautify and complete it."
39
+ )
40
+
41
+ iface.launch()