Spaces:
Runtime error
Runtime error
123LETSPLAY
commited on
Commit
•
f8307bc
1
Parent(s):
415fcfa
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import pipeline
|
2 |
+
import gradio as gr
|
3 |
+
|
4 |
+
# Load the text generation pipeline
|
5 |
+
pipe = pipeline("text-generation", model="google/gemma-2-2b-jpn-it")
|
6 |
+
|
7 |
+
def generate_text(messages):
|
8 |
+
# Extracting the content from the messages
|
9 |
+
user_message = messages["content"]
|
10 |
+
|
11 |
+
# Using the pipeline to generate a response
|
12 |
+
result = pipe(user_message, max_length=50, num_return_sequences=1)
|
13 |
+
|
14 |
+
# Return the generated text
|
15 |
+
return result[0]["generated_text"]
|
16 |
+
|
17 |
+
# Set up Gradio interface
|
18 |
+
with gr.Blocks() as demo:
|
19 |
+
gr.Markdown("# Text Generation with Hugging Face's gemma-2-2b-jpn-it")
|
20 |
+
|
21 |
+
# Input for user's message
|
22 |
+
user_input = gr.Textbox(label="Your Message", placeholder="Type a message", value="Who are you?")
|
23 |
+
|
24 |
+
# Output for generated response
|
25 |
+
output_text = gr.Textbox(label="Generated Response")
|
26 |
+
|
27 |
+
# Button to trigger text generation
|
28 |
+
generate_button = gr.Button("Generate Response")
|
29 |
+
|
30 |
+
# Link button click with text generation function
|
31 |
+
generate_button.click(fn=generate_text, inputs={"content": user_input}, outputs=output_text)
|
32 |
+
|
33 |
+
# Launch the Gradio app
|
34 |
+
demo.launch()
|