DKethan commited on
Commit
6836be3
·
verified ·
1 Parent(s): 9ad7e89

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -9
app.py CHANGED
@@ -1,19 +1,22 @@
1
  import gradio as gr
2
  from huggingface_hub import InferenceClient
3
 
4
- # Load the text generation pipeline
5
  generator = InferenceClient("mistralai/Codestral-22B-v0.1")
6
 
7
  # Define the function for text generation
8
  def generate(text):
9
- # Use the `text_generation` method for generating text
10
- result = generator.text_generation(
11
- inputs=text,
12
- max_length=100,
13
- num_return_sequences=1
14
- )
15
- # Extract and return the generated text
16
- return result[0]['generated_text'] if 'generated_text' in result[0] else "Error: Failed to generate text"
 
 
 
17
 
18
  # Define examples
19
  examples = [
 
1
  import gradio as gr
2
  from huggingface_hub import InferenceClient
3
 
4
+ # Load the text generation model
5
  generator = InferenceClient("mistralai/Codestral-22B-v0.1")
6
 
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
 
21
  # Define examples
22
  examples = [