File size: 1,031 Bytes
4309fc8
faa579e
 
4309fc8
faa579e
4309fc8
 
 
 
 
 
 
 
 
 
dce5444
b6144f6
 
279e516
 
 
b6144f6
279e516
faa579e
279e516
faa579e
 
279e516
faa579e
279e516
 
faa579e
 
279e516
faa579e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import os
import gradio as gr
from transformers import pipeline
from huggingface_hub import login

# Read the token from the environment variable
HUGGINGFACE_TOKEN = os.getenv("HUGGINGFACE_TOKEN")

# Authenticate with Hugging Face
if HUGGINGFACE_TOKEN:
    login(token=HUGGINGFACE_TOKEN)
else:
    raise ValueError("Hugging Face token not found in environment variables.")

# Initialize the text generation pipeline
pipe = pipeline("text-generation", model="TinyLlama/TinyLlama-1.1B-Chat-v1.0")

def generate_response(user_input):
    # Generate text based on the user's input
    response = pipe(user_input, max_length=100, num_return_sequences=1)
    # Extract the generated text
    generated_text = response[0]['generated_text']
    return generated_text

# Create the Gradio interface
interface = gr.Interface(
    fn=generate_response,
    inputs=gr.Textbox(label="prompt:", lines=2, placeholder="prompt"),
    outputs="text",
    title="Gemma",
    description="Prompt gemma-2b"
)

# Launch the Gradio app
interface.launch()