Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,35 +1,21 @@
|
|
| 1 |
-
|
| 2 |
-
from
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
# Tokenize input and move tensors to device
|
| 24 |
-
inputs = tokenizer.encode(prompt, return_tensors="pt").to(device)
|
| 25 |
-
|
| 26 |
-
# Generate output tokens (you can tweak max_length)
|
| 27 |
-
outputs = model.generate(inputs, max_length=50, do_sample=True, top_k=50, top_p=0.95)
|
| 28 |
-
|
| 29 |
-
# Decode tokens to string
|
| 30 |
-
generated_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 31 |
-
|
| 32 |
-
return jsonify({'generated_text': generated_text})
|
| 33 |
-
|
| 34 |
-
if __name__ == '__main__':
|
| 35 |
-
app.run(debug=True)
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
from openai import OpenAI
|
| 3 |
+
|
| 4 |
+
client = OpenAI(
|
| 5 |
+
base_url="https://router.huggingface.co/v1",
|
| 6 |
+
api_key=os.environ["HF_TOKEN"],
|
| 7 |
+
)
|
| 8 |
+
|
| 9 |
+
stream = client.chat.completions.create(
|
| 10 |
+
model="openai/gpt-oss-20b",
|
| 11 |
+
messages=[
|
| 12 |
+
{
|
| 13 |
+
"role": "user",
|
| 14 |
+
"content": "What is the capital of France?"
|
| 15 |
+
}
|
| 16 |
+
],
|
| 17 |
+
stream=True,
|
| 18 |
+
)
|
| 19 |
+
|
| 20 |
+
for chunk in stream:
|
| 21 |
+
print(chunk.choices[0].delta.content, end="")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|