Chan-Y commited on
Commit
b700186
1 Parent(s): 43e35e5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -4
app.py CHANGED
@@ -1,15 +1,23 @@
1
  import gradio as gr
2
- from transformers import pipeline
3
 
4
  # Load the text-generation pipeline with Mistral model
5
- pipe = pipeline("text-generation", model="mistralai/Mistral-7B-Instruct-v0.3")
6
 
 
 
 
 
 
 
 
 
 
7
  # Define the function to process user input
8
  def classify_text(text):
9
  prompt = "Classify the following text into a category or topic:"
10
  input_text = f"{prompt}\n{text}"
11
- results = pipe(input_text, max_length=100, num_return_sequences=1)
12
- return results[0]['generated_text']
13
 
14
  # Create Gradio interface
15
  interface = gr.Interface(
 
1
  import gradio as gr
 
2
 
3
  # Load the text-generation pipeline with Mistral model
4
+ from langchain_huggingface import HuggingFaceEndpoint
5
 
6
+
7
+ # Initialize the LLM and other components
8
+ llm = HuggingFaceEndpoint(
9
+ repo_id="mistralai/Mistral-7B-Instruct-v0.3",
10
+ task="text-generation",
11
+ max_new_tokens=4096,
12
+ temperature=0.5,
13
+ do_sample=False,
14
+ )
15
  # Define the function to process user input
16
  def classify_text(text):
17
  prompt = "Classify the following text into a category or topic:"
18
  input_text = f"{prompt}\n{text}"
19
+ results = llm.invoke(input_text)
20
+ return results
21
 
22
  # Create Gradio interface
23
  interface = gr.Interface(