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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -16
app.py CHANGED
@@ -1,30 +1,26 @@
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
- # 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
 
22
  # Define examples
23
  examples = [
24
- ["What is the fundamental difference between supervised and unsupervised learning"],
25
- ["What is overfitting in supervised learning"],
26
- ["What is a convolutional neural network"],
27
- ["Describe the concept of transfer learning and its significance in deep learning"]
28
  ]
29
 
30
  # Create the Gradio interface
 
1
  import gradio as gr
2
+ from transformers import pipeline
3
 
4
+ # Load the text generation pipeline
5
+ pipe = pipeline("text-generation", model="mistralai/Codestral-22B-v0.1")
6
 
7
  # Define the function for text generation
8
  def generate(text):
9
  try:
10
+ # Format the input and generate text
11
+ messages = [{"role": "user", "content": text}]
12
+ result = pipe(messages, max_length=100, num_return_sequences=1)
13
+ # Extract the generated text
14
+ return result[0]['generated_text'] if result else "Error: No text generated."
 
 
 
 
15
  except Exception as e:
16
  return f"Error: {e}"
17
 
18
  # Define examples
19
  examples = [
20
+ ["Who are you?"],
21
+ ["Explain the difference between AI and ML."],
22
+ ["What is overfitting in machine learning?"],
23
+ ["Describe transfer learning and its importance."]
24
  ]
25
 
26
  # Create the Gradio interface