Spaces:
Runtime error
Runtime error
redfernstech
commited on
Commit
•
73cccaf
1
Parent(s):
841c49c
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import pipeline
|
2 |
+
import gradio as gr
|
3 |
+
|
4 |
+
# Initialize the pipeline
|
5 |
+
pipe = pipeline("text-generation", model="nvidia/OpenMath2-Llama3.1-8B")
|
6 |
+
|
7 |
+
# Define a function that takes user input and uses the pipeline to generate a response
|
8 |
+
def generate_response(messages):
|
9 |
+
# Prepare the input format for text generation
|
10 |
+
conversation = [{"role": "user", "content": messages}]
|
11 |
+
response = pipe(conversation)[0]['generated_text']
|
12 |
+
return response
|
13 |
+
|
14 |
+
# Set up the Gradio interface
|
15 |
+
iface = gr.Interface(
|
16 |
+
fn=generate_response, # Function to call
|
17 |
+
inputs="text", # Input type: text
|
18 |
+
outputs="text", # Output type: text
|
19 |
+
title="Text Generation with Llama 3.1",
|
20 |
+
description="Ask questions or have a conversation with Llama 3.1",
|
21 |
+
)
|
22 |
+
|
23 |
+
# Launch the interface
|
24 |
+
iface.launch()
|