Update app.py
Browse files
app.py
CHANGED
@@ -7,7 +7,17 @@ model = pipeline("text-generation", model="rish13/polymers")
|
|
7 |
def generate_response(prompt):
|
8 |
# Generate text from the model
|
9 |
response = model(prompt, max_length=150, num_return_sequences=1)
|
10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
|
12 |
# Define the Gradio interface
|
13 |
interface = gr.Interface(
|
|
|
7 |
def generate_response(prompt):
|
8 |
# Generate text from the model
|
9 |
response = model(prompt, max_length=150, num_return_sequences=1)
|
10 |
+
generated_text = response[0]['generated_text']
|
11 |
+
|
12 |
+
# Find the position of the first end-of-sentence punctuation
|
13 |
+
end_punctuation = ['.', '!', '?']
|
14 |
+
end_position = min((generated_text.find(punct) for punct in end_punctuation if punct in generated_text), default=-1)
|
15 |
+
|
16 |
+
if end_position != -1:
|
17 |
+
# Include the punctuation in the response
|
18 |
+
generated_text = generated_text[:end_position + 1]
|
19 |
+
|
20 |
+
return generated_text
|
21 |
|
22 |
# Define the Gradio interface
|
23 |
interface = gr.Interface(
|