Spaces:
Sleeping
Sleeping
Update2
Browse files
app.py
CHANGED
@@ -1,20 +1,24 @@
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
3 |
|
4 |
-
# Load a
|
5 |
-
model_name = "gpt2" #
|
6 |
generator = pipeline("text-generation", model=model_name)
|
7 |
|
8 |
# Inference function
|
9 |
-
def
|
10 |
-
|
|
|
|
|
11 |
|
12 |
# Gradio interface
|
13 |
-
interface = gr.Interface(
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
|
|
|
|
18 |
|
19 |
# Launch the interface
|
20 |
interface.launch()
|
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
3 |
|
4 |
+
# Load a more suitable model for conversational responses
|
5 |
+
model_name = "gpt2" # You might want to try 'gpt-neo' or 'gpt-3.5-turbo' if available
|
6 |
generator = pipeline("text-generation", model=model_name)
|
7 |
|
8 |
# Inference function
|
9 |
+
def generate_response(prompt):
|
10 |
+
# Generate text with a more structured approach
|
11 |
+
response = generator(prompt, max_length=100, num_return_sequences=1)[0]['generated_text']
|
12 |
+
return response.strip() # Clean up any leading/trailing whitespace
|
13 |
|
14 |
# Gradio interface
|
15 |
+
interface = gr.Interface(
|
16 |
+
fn=generate_response,
|
17 |
+
inputs="text",
|
18 |
+
outputs="text",
|
19 |
+
title="Conversational LLM",
|
20 |
+
description="Enter a message to receive a relevant response."
|
21 |
+
)
|
22 |
|
23 |
# Launch the interface
|
24 |
interface.launch()
|