Update app.py
Browse files
app.py
CHANGED
@@ -1,23 +1,26 @@
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
3 |
|
4 |
-
#
|
5 |
-
|
6 |
|
7 |
-
def
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
|
|
|
|
|
|
13 |
|
14 |
-
# Create Gradio
|
15 |
iface = gr.Interface(
|
16 |
-
fn=
|
17 |
inputs="text",
|
18 |
outputs="text",
|
19 |
title="Ask Any Question",
|
20 |
-
description="Ask
|
21 |
)
|
22 |
|
23 |
iface.launch()
|
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
3 |
|
4 |
+
# Use a different LLM (GPT-Neo instead of GPT-2)
|
5 |
+
generator = pipeline('text-generation', model='EleutherAI/gpt-neo-125M')
|
6 |
|
7 |
+
def generate_text(prompt):
|
8 |
+
generated = generator(
|
9 |
+
prompt,
|
10 |
+
max_length=20, # Limit response length
|
11 |
+
do_sample=False, # Make output deterministic
|
12 |
+
temperature=0.1, # Reduce randomness
|
13 |
+
repetition_penalty=2.0 # Prevent repeating words
|
14 |
+
)
|
15 |
+
return generated[0]['generated_text']
|
16 |
|
17 |
+
# Create the Gradio interface
|
18 |
iface = gr.Interface(
|
19 |
+
fn=generate_text,
|
20 |
inputs="text",
|
21 |
outputs="text",
|
22 |
title="Ask Any Question",
|
23 |
+
description="Ask a question and get an answer using GPT-Neo."
|
24 |
)
|
25 |
|
26 |
iface.launch()
|