Update app.py
Browse files
app.py
CHANGED
|
@@ -12,21 +12,30 @@ model = pipeline(
|
|
| 12 |
device=device # Automatically use GPU if available, otherwise CPU
|
| 13 |
)
|
| 14 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
def generate_response(prompt):
|
| 16 |
# Generate text from the model
|
| 17 |
response = model(
|
| 18 |
prompt,
|
| 19 |
max_length=50, # Adjusted to generate shorter text
|
| 20 |
num_return_sequences=1,
|
| 21 |
-
temperature=0.
|
| 22 |
-
top_k=
|
| 23 |
-
top_p=0.
|
| 24 |
)
|
| 25 |
|
| 26 |
# Get the generated text from the response
|
| 27 |
generated_text = response[0]['generated_text']
|
| 28 |
|
| 29 |
-
|
|
|
|
|
|
|
|
|
|
| 30 |
|
| 31 |
# Define the Gradio interface
|
| 32 |
interface = gr.Interface(
|
|
|
|
| 12 |
device=device # Automatically use GPU if available, otherwise CPU
|
| 13 |
)
|
| 14 |
|
| 15 |
+
def remove_duplicate_sentences(text):
|
| 16 |
+
# Split text into sentences (assuming sentences are separated by periods)
|
| 17 |
+
sentences = text.split('. ')
|
| 18 |
+
unique_sentences = list(dict.fromkeys(sentences)) # Remove exact duplicates
|
| 19 |
+
return '. '.join(unique_sentences)
|
| 20 |
+
|
| 21 |
def generate_response(prompt):
|
| 22 |
# Generate text from the model
|
| 23 |
response = model(
|
| 24 |
prompt,
|
| 25 |
max_length=50, # Adjusted to generate shorter text
|
| 26 |
num_return_sequences=1,
|
| 27 |
+
temperature=0.6, # Increased to add more randomness
|
| 28 |
+
top_k=100, # Increased to allow a wider selection of words
|
| 29 |
+
top_p=0.95 # Slightly increased cumulative probability threshold
|
| 30 |
)
|
| 31 |
|
| 32 |
# Get the generated text from the response
|
| 33 |
generated_text = response[0]['generated_text']
|
| 34 |
|
| 35 |
+
# Post-process to remove duplicate sentences
|
| 36 |
+
processed_text = remove_duplicate_sentences(generated_text)
|
| 37 |
+
|
| 38 |
+
return processed_text
|
| 39 |
|
| 40 |
# Define the Gradio interface
|
| 41 |
interface = gr.Interface(
|