DKethan commited on
Commit
34fa60f
·
verified ·
1 Parent(s): 6836be3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -7
app.py CHANGED
@@ -7,14 +7,15 @@ generator = InferenceClient("mistralai/Codestral-22B-v0.1")
7
  # Define the function for text generation
8
  def generate(text):
9
  try:
10
- # Use the `text_generation` method correctly
11
- result = generator.text_generation(
12
- text, # Pass the text input directly
13
- max_length=100,
14
- num_return_sequences=1
15
- )
16
  # Extract and return the generated text
17
- return result["generated_text"] if "generated_text" in result else "Error: No text generated."
 
 
 
 
 
18
  except Exception as e:
19
  return f"Error: {e}"
20
 
 
7
  # Define the function for text generation
8
  def generate(text):
9
  try:
10
+ # Generate text using the correct API call
11
+ result = generator.text_generation(text, details=True, stream=False)
 
 
 
 
12
  # Extract and return the generated text
13
+ if "generated_text" in result:
14
+ return result["generated_text"]
15
+ elif isinstance(result, list) and len(result) > 0:
16
+ return result[0] # If the response is a list, return the first item
17
+ else:
18
+ return "Error: Unable to generate text."
19
  except Exception as e:
20
  return f"Error: {e}"
21