Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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(
|
16 |
+
fn=classify_text,
|
17 |
+
inputs=gr.Textbox(lines=4, placeholder="Enter your text here..."),
|
18 |
+
outputs=gr.Textbox(lines=4),
|
19 |
+
title="Text Classification with Mistral",
|
20 |
+
description="Enter some text to classify it into a category or topic using the Mistral-7B-Instruct-v0.3 model."
|
21 |
+
)
|
22 |
+
|
23 |
+
# Launch the app
|
24 |
+
if __name__ == "__main__":
|
25 |
+
interface.launch()
|