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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -5
app.py CHANGED
@@ -1,13 +1,19 @@
1
  import gradio as gr
2
- from transformers import pipeline
3
 
4
  # Load the text generation pipeline
5
- generator = pipeline('text-generation', model='gpt2')
6
 
7
  # Define the function for text generation
8
  def generate(text):
9
- result = generator(text, max_length=100, num_return_sequences=1)
10
- return result[0]['generated_text']
 
 
 
 
 
 
11
 
12
  # Define examples
13
  examples = [
@@ -26,4 +32,5 @@ run = gr.Interface(
26
  )
27
 
28
  # Launch the app
29
- run.launch()
 
 
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 = [
 
32
  )
33
 
34
  # Launch the app
35
+ if __name__ == "__main__":
36
+ run.launch()