Spaces:
No application file
No application file
Update app.py
Browse files
app.py
CHANGED
@@ -1,30 +1,7 @@
|
|
1 |
-
|
2 |
-
from transformers import AutoModelForCausalLM, AutoTokenizer
|
3 |
-
import torch
|
4 |
|
5 |
-
|
6 |
-
model_name = "distilgpt2" # This is a smaller version of GPT-2
|
7 |
-
model = AutoModelForCausalLM.from_pretrained(model_name)
|
8 |
-
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
9 |
|
10 |
-
|
11 |
-
def
|
12 |
-
|
13 |
-
inputs = tokenizer.encode(user_input, return_tensors="pt")
|
14 |
-
|
15 |
-
# Generate a response from the model
|
16 |
-
with torch.no_grad(): # Disable gradient calculation for inference
|
17 |
-
outputs = model.generate(inputs, max_length=100, num_return_sequences=1, no_repeat_ngram_size=2, top_p=0.9, top_k=50)
|
18 |
-
|
19 |
-
# Decode the generated response
|
20 |
-
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
21 |
-
|
22 |
-
return response
|
23 |
-
|
24 |
-
# Create Gradio interface for text input and output
|
25 |
-
iface = gr.Interface(fn=generate_response, inputs="text", outputs="text",
|
26 |
-
title="DistilGPT-2 Chatbot",
|
27 |
-
description="A lightweight conversational chatbot using DistilGPT-2.")
|
28 |
-
|
29 |
-
# Launch the Gradio app
|
30 |
-
iface.launch()
|
|
|
1 |
+
from fastapi import FastAPI
|
|
|
|
|
2 |
|
3 |
+
app = FastAPI()
|
|
|
|
|
|
|
4 |
|
5 |
+
@app.get("/")
|
6 |
+
def greet_json():
|
7 |
+
return {"Hello": "World!"}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|