rish13 commited on
Commit
01ca18e
·
verified ·
1 Parent(s): ac7c0c8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -13
app.py CHANGED
@@ -12,30 +12,21 @@ model = pipeline(
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=130, # Adjusted to generate shorter text
26
  num_return_sequences=1,
27
  temperature=0.7, # Increased to add more randomness
28
- top_k=130, # 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(
@@ -46,5 +37,5 @@ interface = gr.Interface(
46
  description="A model fine-tuned for generating text related to polymers."
47
  )
48
 
49
- # Launch the interface
50
  interface.launch()
 
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=100, # Adjusted to generate shorter text
20
  num_return_sequences=1,
21
  temperature=0.7, # Increased to add more randomness
22
+ top_k=100, # Increased to allow a wider selection of words
23
  top_p=0.95 # Slightly increased cumulative probability threshold
24
  )
25
 
26
  # Get the generated text from the response
27
  generated_text = response[0]['generated_text']
28
 
29
+ return generated_text
 
 
 
30
 
31
  # Define the Gradio interface
32
  interface = gr.Interface(
 
37
  description="A model fine-tuned for generating text related to polymers."
38
  )
39
 
40
+ # Launch the interface
41
  interface.launch()