Spaces:
Runtime error
Runtime error
Upload app.py with huggingface_hub
Browse files
app.py
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from huggingface_hub import InferenceClient
|
| 2 |
+
|
| 3 |
+
def rewrite_demo_with_hf_inference_client(model_name, input_text):
|
| 4 |
+
"""
|
| 5 |
+
Rewrites the input text using a Hugging Face inference client.
|
| 6 |
+
|
| 7 |
+
Args:
|
| 8 |
+
model_name (str): Name of the Hugging Face model to use for rewriting.
|
| 9 |
+
input_text (str): Text to be rewritten.
|
| 10 |
+
|
| 11 |
+
Returns:
|
| 12 |
+
str: Rewritten text.
|
| 13 |
+
"""
|
| 14 |
+
# Initialize the inference client
|
| 15 |
+
client = InferenceClient(model=model_name)
|
| 16 |
+
|
| 17 |
+
# Generate the rewritten text
|
| 18 |
+
rewritten_text = client.text_generation(
|
| 19 |
+
prompt=input_text,
|
| 20 |
+
max_new_tokens=100,
|
| 21 |
+
do_sample=True,
|
| 22 |
+
temperature=0.7,
|
| 23 |
+
top_p=0.9
|
| 24 |
+
)
|
| 25 |
+
|
| 26 |
+
return rewritten_text
|
| 27 |
+
|
| 28 |
+
# Example usage
|
| 29 |
+
if __name__ == "__main__":
|
| 30 |
+
model = "gpt2" # Example model; replace with your preferred model
|
| 31 |
+
input_text = "The quick brown fox jumps over the lazy dog."
|
| 32 |
+
rewritten_text = rewrite_demo_with_hf_inference_client(model, input_text)
|
| 33 |
+
print("Original text:", input_text)
|
| 34 |
+
print("Rewritten text:", rewritten_text)
|