Spaces:
Runtime error
Runtime error
File size: 957 Bytes
0047098 418756d 77bfe0b 418756d 77bfe0b |
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 36 37 38 39 40 41 42 43 |
import gradio as gr
import random
import time
endpoint_url = "https://ko60a2m26ylqgri6.us-east-1.aws.endpoints.huggingface.cloud"
# Streaming Client
client = InferenceClient(endpoint_url, token=hf_token)
def generate_text(prompt):
"""Generates text using the Hugging Face Inference API."""
chat_prompt = f"""
### Instruction:
You are a chatbot. Chat in Urdu
### Input:
{prompt}
### Response:
""
"""
stream = client.text_generation(chat_prompt, stream=True, details=True, **gen_kwargs)
generated_text = ""
for r in stream:
if r.token.special:
continue
if r.token.text in gen_kwargs["stop"]:
break
generated_text += r.token.text
yield generated_text
iface = gr.Interface(
fn=generate_text,
inputs=gr.Textbox(lines=2, placeholder="Enter your prompt here..."),
outputs="text",
title="Urdu Chatbot",
description="Ask me anything in Urdu!",
)
iface.launch()
|